2014-10-31 34 views
0

我的Android应用程序包含链接,我想在Facebook上分享此链接。我用Intent.ACTION_SEND但为什么Activity Chooser没有显示Facebook和Youtube不会显示在Android Activity Chooser

Facebook的图标,我的代码:

 Intent sharing = new Intent(Intent.ACTION_SEND); 

     sharing.setType("text/html"); 

     sharing.putExtra(Intent.EXTRA_SUBJECT, "Check out this video"); 

     sharing.putExtra(Intent.EXTRA_TEXT, 
       "https://www.youtube.com/watch?v=" + videoUrl); 

     startActivity(Intent.createChooser(sharing, "What to share?")); 

回答

1

变化

sharing.setType("text/html"); 

sharing.setType("text/plain"); 

这种修改在这里解决了这个问题。希望它能帮助你!

此外,请检查以下用于使用特定应用共享链接的代码:http://pastebin.com/JhYzdL4s

+0

它不工作:( – Binngokute 2014-10-31 18:09:24

+1

这是我使用使用特定的应用程序,包括Facebook共享文本的代码。它在这里完美的工作。其他应用程序出现在选择器?也许你的问题与Facebook应用程序本身有关http://pastebin.com/JhYzdL4s – 2014-10-31 18:30:53

+0

不错!我工作:) – Binngokute 2014-11-01 03:32:18

0

我认为你需要为你的共享意图设置包。

例如,如果你想设置一个Facebook的包,你需要做的:

List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0); 
for (ResolveInfo info : resInfo) { 
     String packageName = info.activityInfo.packageName; 
     if(packageName.toLowerCase().contains("facebook")) { 
      share.setPackage(info.activityInfo.packageName); 
     } 
} 
+0

我不工作,我检查了这一点,但没有包含“Facebook”,即使Facebook应用程序已安装 – Binngokute 2014-10-31 18:10:54

+0

也许你需要将包名转换为小写。请检查我编辑的代码。 – ztan 2014-10-31 18:13:23

+0

还是一样! :( – Binngokute 2014-10-31 18:18:47