10

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

Alex248
  • 427
  • 4
  • 15

1 Answers1

0

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);
Gueorgui Obregon
  • 5,077
  • 3
  • 33
  • 57
Satpal Yadav
  • 81
  • 1
  • 12