Sharing remote images using share action provider

I am trying to create a share action to include some text and an image. That can be shared using different apps. I am using the Share Action Provider documented decently well officially.

However, I want to share a remote image for which I have the URL.

I am following the guidelines outlined in this tutorial.

I try to save the remote image into an imageView and get the bitmap out of it and then save that image locally to get the URI to include with the intent. Relevant code snippet:

 // Returns the URI path to the Bitmap displayed in specified ImageView  public Uri getLocalBitmapUri(ImageView imageView) {    // Extract Bitmap from ImageView drawable    Drawable drawable = imageView.getDrawable();    Bitmap bmp = null;    if (drawable instanceof BitmapDrawable){     bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap();    } else {     return null;    }    // Store image to default external storage directory    Uri bmpUri = null;    try {       // Use methods on Context to access package-specific directories on external storage.       // This way, you don't need to request external read/write permission.       // See https://youtu.be/5xVh-7ywKpE?t=25m25s       File file =  new File(getFilesDir(),"share_image.png");       FileOutputStream out = new FileOutputStream(file);       bmp.compress(Bitmap.CompressFormat.PNG, 90, out);       out.close();       bmpUri = Uri.fromFile(file);      } catch (IOException e) {         e.printStackTrace();      }      return bmpUri;  } 

I try to save the image in the internal storage so that I don't have to explicitly add permissions to read and write external storage.

This approach doesn't work and I don't get any image when I try to share the content on Whatsapp.(I see the text as image caption but no image). Same with the other apps.

I replace the File path to this:

 File file =  new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "share_image.png"); 

Basically, I just change the internal storage to external storage. And I can confirm that the file is getting properly generated and I am able to share it with other apps.

I can not verify that the app is creating the image (share_image.png) properly in the internal storage but I am assuming it is, as I use the same code entirely.

I am wondering if this is the only way to share a remote image. Do I have to save it in the external storage only? I will have to add permissions in my manifest. It seems a bit weird to me that a user has to accept two permissions just so that they can share images from my app. Why am I not able to share images stored in my app's internal storage? What am I doing wrong here?

Any insight is deeply appreciated.

Replay

Category: internal storage Time: 2016-07-28 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 3.380 (s). 13 q(s)