user2317753
user2317753

Reputation: 33

Android - Open session not working with last Facebook app version and working fine if facebook not installed

i develop facebook application but when it installed to device it works fine if there is no facebook application installed on the device and when the facebook application installed the Session can not be open. My code as below,

Session.openActiveSession(this, true,
            new Session.StatusCallback() {
                // callback when session changes state
                @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 res) {
                                        if (user != null) {
                                            User.getInstance().setProfile(user);

                                        }
                                    }
                                });
                    }
                }
            });

      @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      Session.getActiveSession().onActivityResult(this, requestCode, resultCode,  data);
      if(Session.getActiveSession().isOpened()) {
          Log.i("here opened", "thnx");

      }
}

Upvotes: 0

Views: 1783

Answers (1)

user2317753
user2317753

Reputation: 33

hy guys i want to share this info with you for any one face the above problem.

Some times when you developing facebook application you will need to generate the hash key by keytool "you can generate it by this command keytool -exportcert -alias androiddebugkey -keystore C:\Users\YOURUSER.android\debug.keystore | "C:\bin\bin\openssl" sha1 -binary |"C:\bin\bin\openssl" base64 the enter android as a password ".

The problem in above method it sometimes generate wrong hash key as it depends on the JDK version and used openssl application so your facebook application can not be logged in.

The problem solve you can write below code in your activity and use the generated hash key instead above one and every thing will be working fine.

    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.kartag.gui", 
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }

Upvotes: 2

Related Questions