Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓分享意向。什么应用程序不显示在选择器中_Android_Android Intent - Fatal编程技术网

Android 安卓分享意向。什么应用程序不显示在选择器中

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

我想让我的应用程序的用户能够通过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(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工作不正常。卸载并重新安装。。。