美好的一天,
以下代码适用于从Google Photo应用中选择图片的情况。但是,当我从三星股票库中选择相同的图像时,我的应用程序崩溃了。
我做了一些故障排除,并意识到问题出在 getContentResolver()。query():
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
//Error happens when program try to run the following line of code
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
Toast.makeText(getApplicationContext(), picturePath, Toast.LENGTH_LONG).show();
}
}
请帮帮我。谢谢。