Share image and text through Whatsapp or Facebook

前端 未结 12 910
谎友^
谎友^ 2020-11-28 05:23

I have in my app a share button and i want to share an image and a text at the same time. In GMail it works fine but in WhatsApp, only the image is sent and in Facebook the

12条回答
  •  再見小時候
    2020-11-28 05:44

    Please try the below code and hopefully it will work.

        Uri imgUri = Uri.parse(pictureFile.getAbsolutePath());
        Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
        whatsappIntent.setType("text/plain");
        whatsappIntent.setPackage("com.whatsapp");
        whatsappIntent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share");
        whatsappIntent.putExtra(Intent.EXTRA_STREAM, imgUri);
        whatsappIntent.setType("image/jpeg");
        whatsappIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    
        try {
            activity.startActivity(whatsappIntent);
        } catch (android.content.ActivityNotFoundException ex) {
            ToastHelper.MakeShortText("Whatsapp have not been installed.");
        }
    

提交回复
热议问题