Android 安卓分享意向。什么应用程序不显示在选择器中
我想让我的应用程序的用户能够通过whatsapp共享文本。我使用了whatsapp网站上的描述:Android 安卓分享意向。什么应用程序不显示在选择器中,android,android-intent,Android,Android Intent,我想让我的应用程序的用户能够通过whatsapp共享文本。我使用了whatsapp网站上的描述: Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send."); sendIntent.setType("text/plain"); startActivity(sendInten
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
问题是系统选择器没有显示whatsapp作为选项,尽管它已安装
以android的共享意图进行共享不再可能了吗
感谢您的帮助试试这个:
PackageManager pm=getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "YOUR TEXT HERE";
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 (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
试试这个:
PackageManager pm=getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "YOUR TEXT HERE";
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 (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
在第5行中,用这个替换,它现在应该可以工作了
startActivity(Intent.createChooser(sendIntent, "Share text via.."));
选择器允许用户选择另一个应用程序而不是默认应用程序。在第5行中,替换为该应用程序,它现在应该可以工作了
startActivity(Intent.createChooser(sendIntent, "Share text via.."));
选择器允许用户选择其他应用程序而不是默认应用程序。我收到一条消息,该应用程序未安装。但这不是真的,因为whatsapp肯定已经安装了。这种方法对我很有效。我想您的whatsapp工作不正常。卸载并再次安装…我收到一条消息,该应用程序未安装。但这不是真的,因为whatsapp肯定已经安装了。这种方法对我很有效。我想您的whatsapp工作不正常。卸载并重新安装。。。