2013-06-27 38 views
9

我通過WhatsApp分享我的圖片 - 但我必須選擇收件人。 這裏是我的代碼:通過WhatsApp發送圖像到特定收件人(Android)

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

我爾德喜歡與人直接交流。你們有些人知道我該怎麼做? 感謝

+0

[通過WhatsApp的發送消息]的可能重複(http://stackoverflow.com/questions/15462874/sending- message-through-whatsapp) – rds

+0

發現了什麼? –

回答

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); 
相關問題