如何在Android中将图像从url共享到whatsapp?

时间:2014-09-26 09:26:25

标签: android facebook url android-intent whatsapp

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"));

无法从网址分享图片到什么应用。请建议我如何将图像从网址分享到whatsapp&还有facebook在android ??

谢谢,

尼丁

2 个答案:

答案 0 :(得分: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.");
}

答案 1 :(得分: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) { }
    });