Send message via whatsapp programmatically [closed]
closed. this question is out of scope and is not currently accepting answers.
want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 4 years ago .
improve this questionI've tried some codes but haven't gotten anything yet. I'm raising the possibility of sending one-to-one by going through a loop. Does anyone know how? Follow tutorial that I tried
Https://stackoverflow.com/questions/15462874/sending-message-through-whatsapp
Https://stackoverflow.com/questions/20946461/send-message-by-viber-or-whatsapp-programmatically
Detail: I just want to send, and not start a chat! In this case, I send the message and close the chat.
4
Author: Comunidade, 2014-08-22
1 answers
Try This
PackageManager packageManager = getPackageManager();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
List<ResolveInfo> resolvedInfoList = packageManager.queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : resolvedInfoList) {
if (resolveInfo.activityInfo.packageName.startsWith(getString(R.string.whatsapp_package_name))) {
intent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
break;
}
}
intent.setPackage(getString(R.string.whatsapp_package_name));//com.whatsapp
String text = "Texto a ser compartilhado";
intent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(intent);
It's good you check if the user has WhatsApp installed
3
Author: Esdras, 2014-10-01 00:51:39