[当我点击发送按钮时,我的whatsapp被停止并且什么都不做,甚至没有显示我在catch部分输入的toast。][1] 这是我的代码:
String[] arrStr1=new String[finalList.size()];
finalList.toArray(arrStr1);
// String smsNumber = "9212197079"; //without '+'
try {
Intent sendIntent = new Intent();//"android.intent.action.MAIN");
//sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, arrStr1);
// sendIntent.putStringArrayListExtra(Intent.EXTRA_TEXT,finalList);
// sendIntent.putExtra("jid", smsNumber + "@s.whatsapp.net"); //phone number without "+" prefix
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
} catch(Exception e) {
Toast.makeText(this, "Error/n" + e.toString(), Toast.LENGTH_SHORT).show();
}
答案 0 :(得分:0)
喔!!!我在这里解决了问题是正确的代码......
StringBuilder str=new StringBuilder();
String[] arrStr=new String[finalList.size()];
finalList.toArray(arrStr);
for(i=0;i<arrStr.length;i++){
str.append(arrStr[i]);
str.append("\n");
}
// String smsNumber = "9212197079"; //without '+'
try {
Intent sendIntent = new Intent();//"android.intent.action.MAIN");
//sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, str.toString());
// sendIntent.putStringArrayListExtra(Intent.EXTRA_TEXT,finalList);
// sendIntent.putExtra("jid", smsNumber + "@s.whatsapp.net"); //phone number without "+" prefix
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
} catch(Exception e) {
Toast.makeText(this, "Error/n" + e.toString(), Toast.LENGTH_SHORT).show();
}