如何将图像从服务器共享到whatsapp

时间:2016-07-01 11:11:11

标签: android image android-intent whatsapp

嘿家伙我想要从服务器共享图像到whatsapp但是它给出了错误图像共享失败你能告诉我可以直接分享图像服务器到whatsapp我做错了什么

这是我的代码

Intent shareIntent = new Intent();
            Uri imageUri = Uri.parse("http://stacktoheap.com/images/stackoverflow.png");  // here is my selected url
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.setPackage("com.whatsapp");
            shareIntent.putExtra(Intent.EXTRA_TEXT, img_txt);
            shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
            shareIntent.setType("image/*");
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            try {
                context.startActivity(shareIntent);
            } catch (android.content.ActivityNotFoundException ex) {
                context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.whatsapp")));
            }

帮助我的朋友

2 个答案:

答案 0 :(得分:0)

由于您正在共享图像和文本,因此您遇到了问题

事实上whatsapp不允许同时共享图像和文本,只尝试图像

答案 1 :(得分:0)

我的回答很简单,首先从服务器下载图像,然后在whatsapp上共享图像

试试这段代码

String imagePath =Environment.getExternalStorageDirectory() + "your folderpath"+"imagename";
        File f=new File(imagePath);
        Uri uri = Uri.fromFile(f);
        Intent share = new Intent(Intent.ACTION_SEND);
        share.setPackage("com.whatsapp");
        share.setType("image/jpg");
        share.putExtra(Intent.EXTRA_TEXT,"your text");  //want share text with image
        share.putExtra(Intent.EXTRA_STREAM, uri);
        share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        try {
            startActivity(share);
        } catch (android.content.ActivityNotFoundException ex) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.whatsapp")));
        }