Facebook login fails on some devices

I have implemented the Facebook login and it works fine on some devices/AVDs. My development device is a Gingerbread phone, but testing it with a 4.1.1 device, it simply does not log in. After pressing the facebook button, it shows a blank screen (trying to connect Facebook), and after 1-2 seconds it comes back to the home screen. Also, no errors are toasted or displayed in the Logcat. Oh, and the Facebook application is installed in the device... Any ideas?

UPDATE:

I enabled logging as suggested by Mark Venzke and using this procedure, and I got this warning (twice) on every login attempt (note: testing with a HTC One S phone):

07-05 20:14:50.582: W/PackageManager(605): Unable to load service info ResolveInfo{4171dbf0 com.htc.socialnetwork.facebook.remote.FacebookSyncService p=0 o=0 m=0x108000}

Note the com.htc.socialnetwork.facebook.remote.FacebookSyncService line, so is there any extra step needed for HTC devices?

Also, I'm attaching the code where the login is performed:

private void onSessionStateChange(Session session, SessionState state, Exception exception) {
    if (isResumed) {
        FragmentManager manager = getSupportFragmentManager();
        int backStackSize = manager.getBackStackEntryCount();
        for (int i = 0; i < backStackSize; i++) {
            manager.popBackStack();
        }
        com.facebook.Settings.addLoggingBehavior(LoggingBehavior.REQUESTS);
        if (state.isOpened()) {

            Bundle params = new Bundle();
            params.putString("fields", "id");
            params.putString("limit", "1");             
            Request request = new Request(Session.getActiveSession(), "me", params, HttpMethod.GET, new Callback()
            {

                @Override
                public void onCompleted(Response response)
                {
                    if (response != null)
                    {
                        Log.d("AuthGraphResponse", response.toString());
                        long id;
                        try {
                            id = response.getGraphObject().getInnerJSONObject().getLong("id");
                            app.setFacebookId(id);
                            Log.d("UserID", Long.valueOf(id).toString());
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            });

            RequestAsyncTask task = new RequestAsyncTask(request);
            task.execute();

            showFragment(AUTH, false);
        } else if (state.isClosed()) {
            showFragment(UNAUTH, false);
        }
    }
}

UPDATE 2:

Is it possible that HTC renames the package name of the default Facebook application in all the devices (or some of them, whatever) to com.htc.socialnetwork.facebook (instead of com.facebook.katana) and it leads to this conflict? I don't really think that uninstalling the default app and installing Facebook from Google Play is an acceptable solution (also, I think default apps cannot be uninstalled).

UPDATE 3:

Not solved yet. 19 hours to award the 100 reputation bounty!

UPDATE 4:

Another interesting line of the LogCat:

07-15 10:55:51.718: E/chromium(30475): external/chromium/net/disk_cache/stat_hub.cc:216: [0715/105551:ERROR:stat_hub.cc(216)] StatHub::Init - App com.facebook.katana isn't supported.

Answers


There is certainly a conflict between your stock app and the SDK. So if you don't want to uninnstall the stock HTC app and still use the SDK 3.0 I think your best bet without modying the source code of the sdk would be to disable SSO and login only through webview.

This can easily be done by adding the SessionLoginBehavior.SUPRESS_SSO everytime you try to open a new session. Here is a sample I changed from the SessionLoginSample (LoginUsingActivityActivity) from the Facebook SDK to show you what to do :

@Override
public void onCreate(Bundle savedInstanceState) {
    ...
    Session session = Session.getActiveSession();
    if (session == null) {
        if (savedInstanceState != null) {
            session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
        }
        if (session == null) {
            session = new Session(this);
        }
        Session.setActiveSession(session);

        //add the check, for if session is opened
        if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED) || !session.getState().isOpened()) {
            //Add the suppress SSO behavior to force webview auth dialog to popup
            session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback).setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO));
        }
    }
  ...
}
//then put your code in the statusCallback method or keep it in the session state change listener

Otherwise if you don't mind changing the facebook sdk code, you should check this out


Shirley Facebook login is not broken on all 4.1.1 devices, so it is something with your implementation.

Are you sure the Key Hash is the same on that device as what you have configured on developer.facebook.com? If you used a different dev key, or it was installed by a third-party store, it's possible the key hashes don't match.

Turn on debug logging in the Facebook SDK source code and rebuild it. It is generally off by default for security reasons. Depending on your version of the SDK, it may be in Util.java or some other location, and may be a variable called 'ENABLE_LOG'.


I think facebook login error mostly occur so to solve this issue you follow there tutorial step by step again with patience.

Other wise its very difficult to solve your problem here. So you can refer this link.

http://developers.facebook.com/android/

I hope you will success.


There isn't enough info in your question. so, I'm making a few guesses here.

1)First look into Mike Venzke's answer.

2) If this doesn't work then try this: You need to sign in on you device using SSO (Single Sign On). So here are the steps you can take.

delete the build. reinstall it. and when asked for permissions from your device, allow them.

If you aren't taken back to your app then you need to add these to your manifest file:

<activity
        android:name="com.facebook.LoginActivity"
        android:label="@string/app_name" >
    </activity>
<meta-data android:value="@string/app_id" android:name="com.facebook.sdk.ApplicationId"/>

where app_name and app_id are your respective app Id and app name on your Facebook app page.

Have you added these btw?

you need these permission as well

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

if you post some more info I might be guess the issue.


I think the problem with your Facebook android app in device. So first uninstall the facebook android app from device and check that facebook login working properly or not.


Since Honeycomb you are not able to make internet calls on the main thread, try using an Android AsyncTask or creating a new thread yourself.

http://developer.android.com/reference/android/os/AsyncTask.html


I got this error when using a device with an old version of facebook. Removing facebook completely, or updating the facebook app fixed it.

I'm pretty sure this happens because Facebook for Android used to be just a wrapped WebView of the mobile site.

Also note that some devices (my Incredible 4G LTE) will reinstall the old (webview) version of facebook if you try to remove it.


connect device to eclipse to see logcat. if log cat not running open cmd prompt in windows and run adb restart, (set the adb path first). then you can see logcat running. now open your app and click facebook login button. you can get the correct hash key in yellow colour in log cat. put that key on facebook and now facebook login will work on every device. thanks.


List<String> permissions = new ArrayList<String>();
permissions.add("email");



//start Facebook session
openActiveSession(this, true, new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
        if (session.isOpened()) {
            //make request to the /me API

            Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
                @Override
                public void onCompleted(GraphUser user, Response response) {
                    if (user != null) {
                        String firstName = user.getFirstName();
                        String lastName = user.getLastName();
                        String id = user.getId();
                        String email=null;
                        try {
                            email = user.getProperty("email").toString();
                        } catch (Exception e) {
                            // TODO: handle exception
                        }

                        String gender = (String) user.getProperty("gender");
                        String birthday = user.getBirthday();



                    //welcome.setText("Hello \n" + firstName+"\n"+lastName+"\n"+email+"\n"+gender+"\n"+birthday+"!");




                    if(firstName!=null)
                    {


                          SharedPreferences.Editor editor = settings.edit();

                            editor.putString("fligin", "1");
                            editor.putString("firstName", firstName);
                            editor.putString("lastName", lastName);
                            editor.putString("email", email);
                            editor.putString("gender", gender);
                            editor.putString("birthday", birthday);
                            editor.commit();

                        Intent intent=new Intent(getApplicationContext(), RegistrationOneActivity.class);
                        startActivity(intent);
                        //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );

                        finish();
                    }
                    else {

                        Toast.makeText(getApplicationContext(),"Person information is null", Toast.LENGTH_SHORT).show();

                    finish();
                        }



                    }
                }
            });
         }
     }
 }, permissions);

Try inserting this line where you define your login button in the java source code

LoginButton fb_button = (LoginButton)findViewById(//your resource id);
fb_button.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);

Need Your Help

Oxyplot does not display plots in WPF view

c# wpf plot oxyplot

I'm working with OxyPlot in WPF. Trying to display PlotModels in a UI.

how to bind the values of two different arrays with each other in angular js

javascript jquery angularjs arrays json

hi i'm going to manage the user access levels with angular js and json.