我需要通過whatsapp方法將佈局的所有textview作爲字符串發送,但是如果textview爲null,則必須發送空白文本。通過WhatsApp發送Textviews
這是我的代碼:
public void sendButton(View view) {
// Do something in response to button
PackageManager pm = getPackageManager();
try {
TextView textview3 = (TextView) findViewById(R.id.textAmor3);
TextView textview2 = (TextView) findViewById(R.id.textAmor2);
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
if (textview3 == null) {
} else {
}
String both = textview2 + "-" + textview3;
PackageInfo info = pm.getPackageInfo("com.whatsapp",
PackageManager.GET_META_DATA);
//Check if package exists or not. If not then code
//in catch block will be called
waIntent.setPackage("com.whatsapp");
waIntent.putExtra(Intent.EXTRA_TEXT, both);
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (PackageManager.NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}
}
什麼做我必須做的?
感謝
* #texttext.getText()。toString()。trim(); * – Sanoop
您無法發送視圖。只有文字。 –