Launching camera app

Jack Cole

Well-Known Member
Licensed User
Longtime User
I can launch the android cam app with the following:

B4X:
dim camintent as intent
camintent.Initialize("android.media.action.IMAGE_CAPTURE", "")

But I'd like to use the following, which works with higher API's to provide a full-sized image.

B4X:
dim camintent as intent
camintent.Initialize("MediaStore.ACTION_IMAGE_CAPTURE", "")

I get the following error.
android.conent.ActivityNotFoundException: No Activity found to handle Intent

I wrote a library that I can use to launch the camera using "MediaStore.ACTION_IMAGE_CAPTURE," but I'd rather be able to just launch the intent from B4A.

Any ideas on how to do this? If not I'll stick to the library I created, and can post for others if there is interest.

Thanks,
Jack
 

Informatix

Expert
Licensed User
Longtime User

MediaStore.ACTION_IMAGE_CAPTURE is a constant in the SDK. Its value is:
"android.media.action.IMAGE_CAPTURE"

The size of the returned image is determined by the presence of EXTRA_OUTPUT. Ref
 
Last edited:
Upvote 0

Jack Cole

Well-Known Member
Licensed User
Longtime User
Ok. How can this java code be converted to B4A--if possible?

B4X:
final Uri imageUri = Uri.parse("file://" + destination);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);

I can get a full res image with this code and it also saves an additional copy of the image to destination.
 
Upvote 0

Jack Cole

Well-Known Member
Licensed User
Longtime User
Thanks Erel. I was able to take this to get it to do what I need. I post the final solution here in case others want to use the Android system camera rather than ACL. This will take a picture and save an additional copy of the picture in the directory and file name specified. You can check for the existence of the additional file in activity_resume to do something with the image. It is a full sized image rather than a smaller image.


B4X:
Sub ParseUri(s As String) As Object
    Dim r As Reflector
    Return r.RunStaticMethod("android.net.Uri", "parse", Array As Object(s), Array As String("java.lang.String"))
End Sub

Sub OpenCam(dir as string, fn as string)
    dim camintent as intent
    camintent.Initialize("android.media.action.IMAGE_CAPTURE", "")
    camintent.PutExtra("output",ParseUri("file://" & File.Combine(dir,fn)))
    StartActivity(camintent)
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…