I am using the following code to request an image from the user:
Intent pickIntent = new Intent();
pickIntent.setType("image/* video/*");
pickIntent.setAction(Intent.ACTION_GET_CONTENT);
pickIntent.addCategory(Intent.CATEGORY_OPENABLE);
// child intents to allow capture image and video
Intent capturePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent captureVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
// set max capture size
capturePhotoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, 20971520L); //20*1024*1024=20MB
captureVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, 20971520L); //20*1024*1024=20MB
// present import chooser
String chooserTitle = "Import Media From...";
Intent chooserIntent = Intent.createChooser(pickIntent, chooserTitle);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{capturePhotoIntent, captureVideoIntent});
startActivityForResult(chooserIntent, MEDIA_CAPTURE);
This works on my Nexus 5, but crashes on my Galaxy S5. The crash occurs after I have taken the photo, and tap "Save," but before onActivityResult()
is called. I have also tried supplying a URI via capturePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mUri)
, but the same behavior occurs.
I get no stack trace for my code, since nothing is passed back to my activity; the activity just crashes.
I've been working on this for days. Any advice is appreciated.
I figured out the problem. My app was running out of memory. I solved this by adding android:largeHeap="true"
to my AndroidManifest.xml, as well as redesigning the code that managed the picture data.