不幸的是android系统已停止意图whatsapp

时间:2017-04-18 02:22:50

标签: java android-intent

我正在尝试使用以下代码向whatsapp发送一些消息,但它给出错误android系统已停止但意图工作正常。并且文本也会添加到邮件中。可能是什么问题?

PackageManager pm = getPackageManager();
        try {

            Intent waIntent = new Intent(Intent.ACTION_SEND);
            waIntent.setType("text/plain");
            String text =  " http://play.google.com/  ";
            PackageInfo info = pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
            waIntent.setPackage("com.whatsapp");
            waIntent.putExtra(Intent.EXTRA_TEXT, text);
            startActivity(Intent.createChooser(waIntent, "Share with"));

        } catch (PackageManager.NameNotFoundException e) {
            Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
                    .show();
        }

1 个答案:

答案 0 :(得分:0)

找到this回答

Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "share text");
try {
     startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
     Toast.makeText(this, "Whatsapp not installed", Toast.LENGTH_SHORT).show();
}