我使用的是一个意图是这样的:
I'm using an intent like this:
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
而在 onActivityResult()
我有这样的:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != Activity.RESULT_OK) {
return; // user cancelled
}
Uri imageUri = data.getData();
if (imageUri == null) {
// (code to show error message goes here)
return;
}
// Get image path from media store
String[] filePathColumn = { android.provider.MediaStore.MediaColumns.DATA };
Cursor cursor = this.getContentResolver().query(imageUri, filePathColumn,
null, null, null);
if (cursor == null || !cursor.moveToFirst()) {
// (code to show error message goes here)
return;
}
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String imagePath = cursor.getString(columnIndex);
cursor.close();
if (imagePath == null) {
// error happens here
}
}
当我选择特定的专辑图片类似的的帖子的头像的(见截图),我无法获取图像路径 onActivityResult()
。从其他相册的图片,没有任何问题被选中。
When I select images from particular albums like "Posts", "Profile Photos" (see screenshot) I'm unable to get the image path in onActivityResult()
. Images from other albums can be selected with no problems.
我已经尝试添加 intent.putExtra(返回数据,真)
,但 data.getExtras()返回
。空
()
I've tried adding intent.putExtra("return-data", true)
but data.getExtras()
returns null
in onActivityResult()
.
有similar这里的问题,但没有人回答了这个问题。
There is similar question here, but no one answered it.
请帮忙!
跳这将帮助你......
hops this will helps you ....
ACTIVITYRESULT_CHOOSEPICTURE是调用startActivity时(意向,要求code)使用INT;
ACTIVITYRESULT_CHOOSEPICTURE is the int you use when calling startActivity(intent, requestCode);
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == ACTIVITYRESULT_CHOOSEPICTURE) {
BitmapFactory.Options options = new BitmapFactory.Options();
final InputStream ist = ontext.getContentResolver().openInputStream(intent.getData());
final Bitmap bitmap = BitmapFactory.decodeStream(ist, null, options);
ist.close();
}
}
如果上面的code不低于工作只是指这个链接...这将切切实实的显示方式
if above code doesn't work than just refer this link... it will surly shows the way
http://dimitar.me/how-to-get-picasa-images-using-the-image-picker-on-android-devices-running-any-os-version/
上一篇:什么意图过滤器必须我的应用程序涵盖出现在选配时再审从外部应用程序的图像?应用程序、我的、出现在、过滤器
下一篇:能在Android的AsyncTask doInBackground同步序列化执行任务?能在、任务、序列化、AsyncTask