简体   繁体   English

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

[英]how to share image from sever to whatsapp

hey guys i want to share image from server to whatsapp but its give an error image share failed can you tell me can i share image directly server to whatsapp what i am doing something wrong 大家好,我想将图像从服务器共享到whatsapp,但是它给出了错误的图像共享失败,您能告诉我我可以直接将图像共享到服务器到whatsapp吗?我在做什么错

this is my code 这是我的代码

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

help me friends 帮我啦

You are getting issue because you are sharing image and text both 您遇到了问题,因为您同时共享图像和文本

Infact whatsapp doesn't allow to share image and text simultaneously, try either image only 实际上,WhatsApp不允许同时共享图像和文本,请仅尝试任何一个图像

my answer is simple first download image from sever and then share image on whatsapp 我的答案很简单,首先从服务器下载图像,然后在whatsapp上共享图像

try this code 试试这个代码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM