简体   繁体   中英

Error in Facebook Share Dialog

I encountered an unlike error. I tried to do the Facebook Share Dialog however I encountered this error in the 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.

I have no idea what this means. I tried to search for it but there is no similar instance. Here is my code.

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

    }
};

}

Here is my logcat.:

http://shrib.com/nointentstuff

For those who actually want to build their app for users who may not have Facebook app installed, make sure to include this check around your ShareDialog builder ( more info here ):

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());

}

If the user doesn't have the app installed (ridiculous dependency from FB...) you can fallback to sharing from the browser:

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

com.facebook.FacebookException: Unable to create Intent; this likely means the Facebook app is not installed

Quoting from step 2 @ https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/

The Facebook SDK uses Facebook's native app to provide support for authentication when it's present. On a real device, you can test this by simply installing this app for free from Google Play. However, it's not possible to access Google Play on an emulator. If you want to test the flow there, we include a copy in the SDK that you can install.

The installable APK of the Facebook app is in the bin folder of the SDK, and named FBAndroid-3.5.apk or similar. To install it onto an Android emulator, you'll first need to start the emulator.

Secondly, locate the adb tool in the platform-tools directory of your main Android SDK. On OS X, you will have chosen this location when you unzipped the Android SDK. On Windows, the SDK is installed into your home directory, under AppData\\Local\\Android\\android-sdk

Assuming you've placed the Facebook SDK in your home directory, you use adb to install the APK to the running emulator in OS X like this:

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

And on Windows, like this:

adb install %HOMEPATH%\\facebook-android-sdk-3.5\\bin\\FBAndroid-3.5.apk Once complete, check the apps screen of the emulator to check that the app has been installed correctly. If you need to force the upgrade of this app from a previous version, add the -r flag, like this on OS X:

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

// Manifest File

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

build.gradle compile '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);

}

When Success full Login to facebook then call shareOnFaceboo kMethod its working

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM