Unable to receive share image - Android 6.0

前端 未结 1 918
被撕碎了的回忆
被撕碎了的回忆 2021-01-25 03:44

I am using the code provided by aFileChooser to get able to get the shared image inside my application. Images from the gallery work OK but if i use an image say inside Google C

1条回答
  •  北海茫月
    2021-01-25 04:16

    You cannot and should not attempt to ever get the underlying path corresponding with a URI - in the vast majority of cases your app will never have access to the path itself, but only through the URI.

    Thankfully, you can get the binary data of the image from the URI directly:

    InputStream in;
    Bitmap bitmap = null;
    try {
      in = getContentResolver().openInputStream(imageUri);
      // You could do anything with the InputStream.
      // Here we'll just get the Bitmap at full size
      bitmap = BitmapFactory.decodeStream(in);
    } catch (IOException e) {
      // Something went wrong
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException ignored) {}
      }
    }
    // Now you have a Bitmap.
    

    0 讨论(0)
提交回复
热议问题