Sending image via WhatsApp to specific recipient (Android)

Alex248 picture Alex248 · Jun 27, 2013 · Viewed 7k times · Source

I'm sharing my images via WhatsApp - but I have to choose the recipient. Here is my code:

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

I wold like to share with someone directly. Does some of you know how can I do this. Thanks

Answer

Satpal Yadav picture Satpal Yadav · Jul 30, 2013

You can use Intent.ACTION_SENDTO, but message is not copied to clipboard then:

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