我正在使用以下代码从用户请求图像:
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);
这可以在Nexus 5上使用,但在Galaxy S5上却崩溃。当我拍摄完照片并点击“保存”后,才发生崩溃onActivityResult()
。我也尝试通过提供URI capturePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mUri)
,但是发生了相同的行为。
我没有代码的堆栈跟踪,因为没有任何东西传回到我的活动中。活动崩溃了。
我已经为此工作了好几天。任何建议表示赞赏。
我解决了这个问题。我的应用程序内存不足。我通过添加android:largeHeap="true"
到AndroidManifest.xml以及重新设计用于管理图片数据的代码来解决了这一问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句