从图库中获取图像导致在 [=10th=] 结果中未发现 activity 错误
Get Image from gallery cause no activity found error in activity resulte
我尝试打开图库并让用户从图库中选择图片它在一些 android 上工作但在我的平板电脑 (4.2.2) 上不是全部它工作得很好但我的朋友 (4.1.2 ) 这是 ActivityNotFound Exeption 的原因。
打开图库的代码:
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
try
{
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
catch (ActivityNotFoundException e)
{
e.printStackTrace();
}
这是 ActivityResult 代码:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
picturePath = cursor.getString(columnIndex);
}
尝试:-
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), RESULT_LOAD_IMAGE);
我尝试打开图库并让用户从图库中选择图片它在一些 android 上工作但在我的平板电脑 (4.2.2) 上不是全部它工作得很好但我的朋友 (4.1.2 ) 这是 ActivityNotFound Exeption 的原因。
打开图库的代码:
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
try
{
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
catch (ActivityNotFoundException e)
{
e.printStackTrace();
}
这是 ActivityResult 代码:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
picturePath = cursor.getString(columnIndex);
}
尝试:-
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), RESULT_LOAD_IMAGE);