通过另一个应用程序的WhatsApp发送消息到特定的联系人

是否有可能通过直接从另一个应用程序的whatsapp消息发送到特定的联系人? 我知道联系人ID。 我不想通过意图打开whatsapp 。 我只想直接发送消息像正常的短信。

我已经尝试了其他解决scheme张贴在计算器上,但他们不为我工作。

Solutions Collecting From Web of "通过另一个应用程序的WhatsApp发送消息到特定的联系人"

请让我知道这对你有没有用,

 Uri mUri = Uri.parse("smsto:+9876543210"); Intent mIntent = new Intent(Intent.ACTION_SENDTO, mUri); mIntent.setPackage("com.whatsapp"); mIntent.putExtra("sms_body", "The text goes here"); mIntent.putExtra("chat",true); startActivity(mIntent); 

它不会发送消息,但可以让你打开在whatsapp相同的屏幕:

 private void openWhatsApp() { String smsNumber = "91XXXXXXXX20"; boolean isWhatsappInstalled = whatsappInstalledOrNot("com.whatsapp"); if (isWhatsappInstalled) { Intent sendIntent = new Intent("android.intent.action.MAIN"); sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation")); sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators(smsNumber) + "@s.whatsapp.net");//phone number without "+" prefix startActivity(sendIntent); } else { Uri uri = Uri.parse("market://details?id=com.whatsapp"); Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT).show(); startActivity(goToMarket); } } private boolean whatsappInstalledOrNot(String uri) { PackageManager pm = getPackageManager(); boolean app_installed = false; try { pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); app_installed = true; } catch (PackageManager.NameNotFoundException e) { app_installed = false; } return app_installed; } 

请试试这个,

 public void onClickWhatsApp(View view) { Intent waIntent = new Intent(Intent.ACTION_SEND); waIntent.setType("text/plain"); String text = "YOUR TEXT HERE"; waIntent.setPackage("com.whatsapp"); if (waIntent != null) { waIntent.putExtra(Intent.EXTRA_TEXT, text);// startActivity(Intent.createChooser(waIntent, "Share with")); } else { Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT) .show(); } } 

来源: 请检查这个答案进一步的细节

请试试这个。 它对我来说工作得很好。

  Intent sendIntent = new Intent("android.intent.action.MAIN"); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.setPackage("com.whatsapp"); sendIntent.setType("text/plain"); sendIntent.putExtra("jid", "9194******22" + "@s.whatsapp.net");// here 91 is country code sendIntent.putExtra(Intent.EXTRA_TEXT, "Demo test message"); startActivity(sendIntent);