Android Unable to get path for Cloud image from Photos Application

妖精的绣舞 提交于 2019-12-10 17:16:39

问题


I have tried to getting absolute path and I got the success too but when I try with the cloud images to get that image and used in application file is not find and getting null. I am implementing to receive files from another app like when you select image from Photos, Gallery or File application and share image by using my application.

Here I got the Uri content://com.google.android.apps.photos.contentprovider/0/1/mediaKey%3A%2FAF1QipOFLMMm8uXbeDMQk-P4S0Hx1dlmRDMr4SFABfVi/ACTUAL/61235243

When I select image which is on Google Photos cloud and it'll be first download and then given me above URI. From that point I directly execute in query and getting the name of the file "Filename.png" in all the columns but not the full path.

When same things I tried with the Facebook to share it will display in compose exact which I want to share.

I have also refer this from this link to get the path from Photos application, but the problem is with cloud image.

Anybody have solution or suggestion will be appriciated.


回答1:


Try getting the Bitmap first:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
        Uri selectedImage = data.getData();

        InputStream inputStreamBitmap = null;
        Bitmap imageBitmap = null;
        try {
            inputStreamBitmap = getContentResolver().openInputStream(inputStreamBitmap);
            imageBitmap = BitmapFactory.decodeStream(inputBitmap);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            try {
                if (inputStreamBitmap != null) {
                    inputStreamBitmap.close();
                }
            } catch (IOException ignored) {
            }
        }
        if (imageBitmap != null) {
            processImageBitmap(imageBitmap);
        } else {
            Log.e("ImageIntent", "Error: couldn't open the specified image.");
        }
    }
}

Then you could save the Bitmap to a temp file if you want to.

More details here.



来源:https://stackoverflow.com/questions/32326558/android-unable-to-get-path-for-cloud-image-from-photos-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!