我尝试打开图库并让用户从图库中选择图像,它在某些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);
}
答案 0 :(得分:0)
尝试: -
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), RESULT_LOAD_IMAGE);