只有在对话Facebook和Twitter的应用程序共享按钮 [英] Sharing button with only facebook and twitter apps in dialog

查看:162
本文介绍了只有在对话Facebook和Twitter的应用程序共享按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要分享按钮添加到我的应用程序,而我也做了以下内容:

 最终意图shareIntent =新意图(Intent.ACTION_SEND);
            / *填充数据* /
            shareIntent.setType(纯/文);
            shareIntent.putExtra(Intent.EXTRA_TEXTwww.somesite.com);
            / *把它送上活动,选配* /
            startActivity(Intent.createChooser(shareIntent,共享...));

它显示一个对话框,我没有看到在此对话框Facebook和Twitter。我确实有这两种applicaitons安装在我的手机上。因此,第一问题是,为什么它没有告诉他们?和第二如果以后我会让他们莫名其妙地出现在手机上,如何使对话框只显示Facebook和Twitter,如果用户没有它们,让用户只需通过提供链接到官方应用程序安装。


解决方案

您可以通过以下code检查他们,

<一个href=\"http://stackoverflow.com/questions/6827407/how-to-customize-share-intent-in-android/9229654#9229654\">How定制份额的意图在Android的?

<一个href=\"http://stackoverflow.com/questions/2077008/android-intent-for-twitter-application/9151983#9151983\">Android对于意向Twitter应用


  

我已经看到了很多有关修改应用程序选择器的问题,他们
  似乎都没有这方面,不能更改内置的应用程序选择器,
  但是你可以创建一个使用queryIntentActivities一个自定义应用程序选择器()
  在软件包管理系统类。


  {尝试
    ApplicationInfo信息= getPackageManager()getApplicationInfo(com.facebook.katana,0);
    返回true;
}赶上(PackageManager.NameNotFoundException E){
    返回false;
}
尝试{
    ApplicationInfo信息= getPackageManager()getApplicationInfo(com.twitter.android,0);
    返回true;
}赶上(PackageManager.NameNotFoundException E){
    返回false;
}

I want to add sharing button to my app, and I have done the following:

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..."));

It shows a dialog and I dont see in this dialog facebook and twitter. I do have both these applicaitons installed in my phone. So, first question is why it doesnt show them? And second if later I will make them somehow appear in the phone, how to make that dialog show only facebook and twitter, and if user does not have them, ask user just to install it by giving link to official app.

解决方案

You can check them by using below code,

How to customize share intent in Android?

Android Intent for Twitter application

I've seen a lot of questions about modifying the app chooser, and they all seem to state that no, you cannot change the built-in app chooser, but you can create a custom app chooser using queryIntentActivities() in the PackageManager class.

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;
}

这篇关于只有在对话Facebook和Twitter的应用程序共享按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆