我开始的意图,选择从画廊的照片,但目的总是与结果code RESULT_CANCELED返回。我已经尝试了不同的code很多,但没有什么帮助至极让我觉得也许我失去了一些东西,喜欢把什么东西在活动中的Android清单?
I'm starting an intent to pick a picture from the gallery but the intent always returns with the resultcode RESULT_CANCELED. I have tried alot of different code but nothing helps wich makes me think maybe I am missing something, like putting something in the activity in the Android manifest?
我的code:
// The Intent
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 0);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK){
Uri targetUri = data.getData();
Bitmap bitmap;
try {
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(targetUri));
profileImage.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
将为AP preciate一定的帮助;)
Would appreciate some help ;)
推荐答案
行,所以我解决了这个。我的问题竟然是该onActivityResult()方法被调用的库意图已经完成了。我发现sollution这里:onActivityResult()所谓的prematurely
OK so I solved this. My problem turned out to be that the onActivityResult() method was being called before the Gallery Intent had finished. I found the sollution here: onActivityResult() called prematurely
基本上,我已经指定的活动为singleTask的清单。 将其更改为singleTop解决了这个问题对我来说。
Basically, I had specified the activity to be "singleTask" in the manifest. Changing it to "singleTop" solved it for me.
相关推荐
最新文章