通过WhatsApp向特定收件人发送图片(Android)

10

我通过 WhatsApp 分享我的图片,但我必须选择收件人。

这是我的代码:

   public static void shareImage(Context context,String path, String text, String otherAppPackage){
        Intent share = new Intent(Intent.ACTION_SEND);
        share.setType("image/*");

        share.setPackage("com.whatsapp");

        share.putExtra(android.content.Intent.EXTRA_SUBJECT,  getSubject(context));
        if (text!=null){
            share.putExtra(Intent.EXTRA_TEXT,text);
        }
        if (path!=null){
            share.putExtra(Intent.EXTRA_STREAM,
                    Uri.fromFile(new File(path)));
        }
        context.startActivity(Intent.createChooser(share, context.getString(R.string.share_via)));
    }

我想直接与某人分享。你们中有人知道我该如何做吗?谢谢。


找到了什么吗? - sanedroid
1个回答

0

您可以使用Intent.ACTION_SENDTO,但是消息不会被复制到剪贴板中:

Uri uri = Uri.parse("smsto:+123456789");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.setPackage("com.whatsapp");
it.putExtra("sms_body", "The SMS text");
it.putExtra("chat",true);
startActivity(it);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接