Android的facebook应用程序共享意图

问题描述:

我一直在尝试在Facebook共享意图上共享文本内容,它似乎不让我们共享文本出于某种原因。有谁知道他们为什么这样做?共享文本的唯一方法是使用他们的SDK,这需要时间。只需要一个浪费我时间的理由。谢谢。Android的facebook应用程序共享意图

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
    shareIntent.setType("text/plain"); 
    shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, 
      getString(R.string.share_message_facebook)); 

    PackageManager pm = getActivity().getPackageManager(); 
    List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 
      0); 
    for (final ResolveInfo app : activityList) { 
     if ((app.activityInfo.name).contains("com.facebook") 
       && !(app.activityInfo.name) 
         .contains("com.facebook.messenger")) { 
      final ActivityInfo activity = app.activityInfo; 
      final ComponentName name = new ComponentName(
        activity.applicationInfo.packageName, activity.name); 
      shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); 
      shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
        | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 
      shareIntent.setComponent(name); 
      startActivity(shareIntent); 

      return; 
     } 
    } 
+1

任何人都很难告诉你为什么你的“共享文本内容”代码不起作用,当你的问题不包括该代码。 – CommonsWare

+0

发布你的代码plz –

+0

注释掉整个'PackageManager'的东西,并用'startActivity()'使用原来的'ACTION_SEND''Intent'。如果Facebook出现在选择器中,并选择它,那么你的问题是你对Facebook实现的性质的假设(例如'com.facebook.messenger'包)是有缺陷的。 – CommonsWare

根据他们的policy,你必须控制你的应用程序的用户。如果您想代表他们发布/共享,他们应该事先允许发布权限。因此,您应该使用Facebook SDK。

+1

谢谢。现在我知道我为什么要浪费我的时间...... :)虽然,我仍然生气地让他们为我们创建的每个应用程序在Facebook上创建应用程序。 –