我想从我的应用程序到电报的代码重定向。我没有找到它的任何例子,所以我尝试用与WhatsApp重定向相同的方式来做,它没有工作,你能给我一些建议吗?在我的WhatsApp重定向代码下面,它可以工作,我通过替换字符串" whatsapp"使用" telegram",当检查包的存在时,结果是catch():
PackageManager pm=getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
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, text);
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (PackageManager.NameNotFoundException e) {
Toast.makeText(this, "WhatsApp is not installed", Toast.LENGTH_SHORT)
.show();
}