Mos*_*afa 5 android android-intent
在我的应用程序中,我让用户从他们的图库中选择一张照片 我使用这样的意图:
Intent pickPictureIntent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Run Code Online (Sandbox Code Playgroud)
在我开始这个意图之前,我检查是否有任何应用程序可以处理它:
if (pickPictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(pickPictureIntent, SELECT_PICTURE_FROM_GALLERY_REQUEST_CODE);
}
Run Code Online (Sandbox Code Playgroud)
但是当我的两个用户尝试从他们的图库中选择一张照片时会遇到此异常:
Exception android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.PICK dat=content://media/external/images/media }
Run Code Online (Sandbox Code Playgroud)
到目前为止,我知道当没有活动来处理意图时会发生这种情况,但正如你所看到的,我检查了没有活动来处理我的代码中的意图的可能性.
Jay*_*tel 11
试试这个:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
Run Code Online (Sandbox Code Playgroud)
这会打开文档应用程序.要允许用户也使用他们可能已安装的任何图库应用:
Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
getIntent.setType("image/*");
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.setType("image/*");
Intent chooserIntent = Intent.createChooser(getIntent, "Select Image");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});
startActivityForResult(chooserIntent, PICK_IMAGE);
Run Code Online (Sandbox Code Playgroud)