Android Unable to get path for Cloud image from Ph

2019-07-10 16:01发布

问题:

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.