1

我遇到了一个不同的错误。我尝试执行 Facebook 共享对话框,但在 logcat 中遇到此错误。

 10-17 15:44:39.026: E/AndroidRuntime(2534): com.facebook.FacebookException: Unable to create Intent; this likely means the Facebook app is not installed.

我不知道这是什么意思。我试图搜索它,但没有类似的实例。这是我的代码。

TabFour.java

public class TabFour extends Fragment {
private UiLifecycleHelper uiHelper;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.activity_tab_four, container, false);

    return rootView;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(getActivity(), callback);
    uiHelper.onCreate(savedInstanceState);

    OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
    action.setProperty("book", "https://example.com/book/Snow-Crash.html");

    @SuppressWarnings("deprecation")
    FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "books.reads", "book")
            .build();
    uiHelper.trackPendingDialogCall(shareDialog.present());
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() {
        @Override
        public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
            Log.e("Activity", String.format("Error: %s", error.toString()));
        }

        @Override
        public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
            Log.i("Activity", "Success!");
        }
    });
}



@Override
public void onResume() {
    super.onResume();
    uiHelper.onResume();
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    uiHelper.onSaveInstanceState(outState);
}

@Override
public void onPause() {
    super.onPause();
    uiHelper.onPause();
}

@Override
public void onDestroy() {
    super.onDestroy();
    uiHelper.onDestroy();
}
private Session.StatusCallback callback = new Session.StatusCallback() {


    @Override
    public void call(Session session, SessionState state,
            Exception exception) {
        // TODO Auto-generated method stub

    }
};

}

这是我的日志:

http://shrib.com/nointentstuff

4

4 回答 4

17

对于那些真正想为可能没有安装 Facebook 应用程序的用户构建应用程序的人,请确保在您的 ShareDialog 构建器周围包含此检查(更多信息在这里):

if (FacebookDialog.canPresentShareDialog(getApplicationContext(), 
                                         FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
    FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
            .setLink("https://developers.facebook.com/android")
            .build();
    uiHelper.trackPendingDialogCall(shareDialog.present());

}
于 2013-10-29T18:10:00.223 回答
12

如果用户没有安装应用程序(来自 FB 的可笑依赖...),您可以回退到从浏览器共享:

String linkString = "https://developers.facebook.com/android";
if (FacebookDialog.canPresentShareDialog(getApplicationContext(), FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
    FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this).setLink(linkString).build();
    uiHelper.trackPendingDialogCall(shareDialog.present());
} else {
    String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + linkString;
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
    this.startActivity(intent);
}
于 2014-11-05T13:59:27.593 回答
4

com.facebook.FacebookException:无法创建意图;这可能意味着未安装 Facebook 应用

引用第 2 步 @ https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/

Facebook SDK 使用 Facebook 的本机应用程序来提供对身份验证的支持。在真实设备上,您只需从 Google Play 免费安装此应用程序即可进行测试。但是,无法在模拟器上访问 Google Play。如果您想在那里测试流程,我们在 SDK 中包含一个您可以安装的副本。

Facebook 应用的可安装 APK 位于 SDK 的 bin 文件夹中,名称为 FBAndroid-3.5.apk 或类似名称。要将其安装到 Android 模拟器上,您首先需要启动模拟器。

其次,在您的主要 Android SDK 的 platform-tools 目录中找到 adb 工具。在 OS X 上,您将在解压缩 Android SDK 时选择此位置。在 Windows 上,SDK 安装在您的主目录中,位于 AppData\Local\Android\android-sdk 下

假设您已将 Facebook SDK 放在您的主目录中,您可以使用 adb 将 APK 安装到 OS X 中正在运行的模拟器中,如下所示:

./adb install ~/facebook-android-sdk-3.5/bin/FBAndroid-3.5.apk

在 Windows 上,像这样:

adb install %HOMEPATH%\facebook-android-sdk-3.5\bin\FBAndroid-3.5.apk 完成后,检查模拟器的应用程序屏幕以检查应用程序是否已正确安装。如果您需要强制从以前的版本升级此应用程序,请添加 -r 标志,在 OS X 上如下所示:

./adb install -r ~/facebook-android-sdk-3.5/bin/FBAndroid-3.5.apk
于 2013-10-21T05:16:10.270 回答
1

//清单文件

<uses-permission android:name="android.permission.INTERNET" />

build.gradle 编译'com.facebook.android:facebook-android-sdk:4.8.0'

    <meta-data
        android:name="com.facebook.sdk.ApplicationName"
        android:value="@string/app_name" />
    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id" />

    <provider
        android:name="com.facebook.FacebookContentProvider"
        android:authorities="com.facebook.app.FacebookContentProvider1854328631556764"
        android:exported="true" />


 private CallbackManager callbackManager;  // Global variable Declare 
private ShareDialog     mFacebookShareDialog;   // Global variable Declare 

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main1);
        FacebookSdk.sdkInitialize(this.getApplicationContext());

  callbackManager = CallbackManager.Factory.create();
        fbloginButton = (LinearLayout) findViewById(R.id.facebook_button);

        mFacebookShareDialog = new ShareDialog(this);

}

当成功完全登录到 facebook 然后调用 shareOnFaceboo kMethod 它的工作

   private void shareOnFacebook(){

        ShareLinkContent shareContent = new ShareLinkContent.Builder()
                .setContentTitle("The Simpson!")
                .setContentUrl(Uri.parse("http://www.codecube.in/airbucks-project"))
                .build();

        mFacebookShareDialog.show(shareContent, ShareDialog.Mode.FEED);

        mFacebookShareDialog.registerCallback( this.callbackManager, new FacebookCallback<Sharer.Result>() {
            @Override
            public void onSuccess(Sharer.Result result) {
                Log.v("MyApp", "Share success!"); //Showed if I press the share or the cancel button
                String postID = result.getPostId();
                Log.v("MyApp", "Share success!" +result);
                Log.v("MyApp", "Share success!" +postID);
                Log.v("MyApp", "Share success!" +result.getPostId());
                Log.v("MyApp", "Share success!" +result.toString());
                Log.v("MyApp", "Share success!" +result);

                CommonMethod.showAlert("Sucesssfully post in Fb  Post id -> " +postID +" Result " +result  ,MainActivity.this);

            }
            @Override
            public void onCancel() {
                Log.v("MyApp", "Share canceled"); //Only showed when I press the close button
                CommonMethod.showAlert("Post onCancel " ,MainActivity.this);
            }

            @Override
            public void onError(FacebookException e) {
                Log.v("MyApp","Share error: " + e.toString());
                CommonMethod.showAlert("Post onError "+e ,MainActivity.this);
            }

        });

    }


    @Override
    protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        callbackManager.onActivityResult(requestCode, resultCode, data);
    }
于 2017-06-12T06:00:41.600 回答