gpt4 book ai didi

Android 从图库中选择一张图片

转载 作者:太空狗 更新时间:2023-10-29 14:59:58 28 4
gpt4 key购买 nike

在 fragment 中,我这样调用画廊 Intent :

         // Create the Intent for Image Gallery.
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, MainActivity.LOAD_IMAGE_RESULTS);

在主要 Activity 中,我使用以下代码处理结果:

public static int LOAD_IMAGE_RESULTS = 1;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.w("reqestCode:",""+requestCode);
if(requestCode == LOAD_IMAGE_RESULTS && data != null && data.getData() != null) {
Uri _uri = data.getData();

//User had pick an image.
Cursor cursor = getContentResolver().query(_uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
cursor.moveToFirst();

//Link to the image
final String imageFilePath = cursor.getString(0);
Log.w("ImageFile",imageFilePath);
cursor.close();
}
}

但是在 onActivityResult 中 requestCode 返回 196609 值。所以我的代码不工作。我该如何解决它?

最佳答案

您说您是从 Fragment 调用它。您是否尝试过在这两个地方收听 onActivityResultActivity 以及 Fragment?值得一试。 :)

关于Android 从图库中选择一张图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27755218/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com