Sending message through WhatsApp

前端 未结 23 2240
萌比男神i
萌比男神i 2020-11-22 09:42

Since I found some older posts, that tell that whatsapp doesn\'t support this, I was wondering if something had changed and if there is a way to open a whatsapp \'chat\' wit

23条回答
  •  死守一世寂寞
    2020-11-22 10:10

    This works to me:

    PackageManager pm = context.getPackageManager();
    try {
        pm.getPackageInfo("com.whatsapp", PackageManager.GET_ACTIVITIES);
        Intent intent = new Intent();
                intent.setComponent(new ComponentName(packageName,
                        ri.activityInfo.name));
                intent.setType("text/plain");
                intent.putExtra(Intent.EXTRA_TEXT, element);
    
    } catch (NameNotFoundException e) {
        ToastHelper.MakeShortText("Whatsapp have not been installed.");
    }
    

提交回复
热议问题