Send message via whatsapp programatically [closed]

3

I tried some codes but I did not get anything yet. I'm raising the possibility of sending one-on-one by looping. Does anyone know how? Follow the tutorial I tried

link

link

Detail: I just want to send, not start a chat! In this case, I send the message and close the chat.

    
asked by anonymous 22.08.2014 / 12:20

1 answer

3

Try this out

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 to check if the user has WhatsApp installed

    
01.10.2014 / 02:24