2014-09-26 50 views
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")); 

无法将图片从网址分享到whats app。请建议我如何可以从url共享图像到whatsapp &也在android的脸?怎样才能将图像从url共享到android中的whatsapp?

感谢,

尼廷

回答

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

它不起作用 – 2014-09-26 10:10:46

0

你需要使用这种方法从毕加索库。

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) { } 
    });