1
String url = "http://www.wikihow.com/images/d/d0/Get-the-URL-for-Pictures-Step-1-Version-2.jpg";


            Intent share = new Intent(Intent.ACTION_SEND);        
            share.setType("image/*");
            share.setPackage("com.whatsapp");

            share.putExtra(android.content.Intent.EXTRA_SUBJECT,  "Subject");
            /*if (text!=null){
                share.putExtra(Intent.EXTRA_TEXT,text);
            }
            if (path!=null){
                share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
            }*/

            share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(url)));               
            context.startActivity(Intent.createChooser(share, "Whats App"));

Cant share image from url to whats app. Please suggest me how can share image from url to whatsapp & also facebook in android??

Thanks,

Nitin

Valery Viktorovsky
  • 6,487
  • 3
  • 39
  • 47
Nitin Karale
  • 789
  • 3
  • 12
  • 34

2 Answers2

0
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + url));
try {
    activity.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
    ToastHelper.MakeShortText("Whatsapp have not been installed.");
}
0

you need to use this method from picasso library.

Picasso.with(getApplicationContext()).load(url).into(new Target() {
        @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("image/*");
            i.putExtra(Intent.EXTRA_STREAM, getLocalBitmapUri(bitmap));
            startActivity(Intent.createChooser(i, "Share Image"));
        }
        @Override public void onBitmapFailed(Drawable errorDrawable) { }
        @Override public void onPrepareLoad(Drawable placeHolderDrawable) { }
    });