将图片缩略图和标题中的文本(如Instagram)共享到WhatsApp Android

时间:2019-09-03 06:00:29

标签: android android-intent whatsapp android-sharing

enter image description here

我需要像附件中的图片一样将内容共享给whatsapp。

标题部分具有图像的缩略图,标题文本和链接。 然后,消息部分具有链接。

消息部分很简单。实施标题部分的任何帮助都会有所帮助。

Intent sendIntent = new Intent();   
sendIntent.setAction(Intent.ACTION_SEND);   
sendIntent.putExtra(Intent.EXTRA_TITLE, "title text");   
sendIntent.putExtra(Intent.EXTRA_TEXT, "message section");   
sendIntent.setType("text/plain"); 
startActivity(sendIntent);

我已经查看了whatsapp的常见问题解答,但他们没有提到根据意图处理过的标签列表。

https://faq.whatsapp.com/en/android/28000012

1 个答案:

答案 0 :(得分:0)

尝试下面的代码

Uri imgUri = Uri.parse(pictureFile.getAbsolutePath());
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.setPackage("com.whatsapp");
    intent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share");
    intent.putExtra(Intent.EXTRA_STREAM, imgUri);
    intent.setType("image/jpeg");
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    try {
        activity.startActivity(intent);
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.MakeText(this,"Whatsapp not found",Toast.LENGTH_SHORT).show();
    }