在对话框中仅与Facebook和Twitter应用程序共享按钮

Dal*_*ler 4 android

我想在我的应用程序中添加共享按钮,并且我已完成以下操作:

final Intent shareIntent = new Intent(Intent.ACTION_SEND);              
            /* Fill it with Data */
            shareIntent.setType("plain/text");
            shareIntent.putExtra(Intent.EXTRA_TEXT, "www.somesite.com");    


            /* Send it off to the Activity-Chooser */
            startActivity(Intent.createChooser(shareIntent, "Share..."));
Run Code Online (Sandbox Code Playgroud)

它显示了一个对话框,我在这个对话框中看不到facebook和twitter.我确实在手机中安装了这两个应用程序.所以,first问题是为什么它不显示它们?而且second如果以后我会让他们莫名其妙地出现在手机上,如何使对话框只显示Facebook和Twitter,并且如果用户没有他们,让用户只需通过提供链接到官方应用程序进行安装.

Tal*_*lha 5

您可以使用以下代码检查它们,

如何在Android中自定义共享意图?

Android Intent for Twitter应用程序

我已经看到很多关于修改app选择器的问题,他们似乎都说不,你不能改变内置的app选择器,但你可以使用PackageManager类中的queryIntentActivities()创建一个自定义应用程序选择器.

try{
    ApplicationInfo info = getPackageManager().getApplicationInfo("com.facebook.katana", 0 );
    return true;
} catch( PackageManager.NameNotFoundException e ){
    return false;
}


try{
    ApplicationInfo info = getPackageManager().getApplicationInfo("com.twitter.android", 0 );
    return true;
} catch( PackageManager.NameNotFoundException e ){
    return false;
}
Run Code Online (Sandbox Code Playgroud)