title: Facebook login not working with FB official app installed on phone
body: <p>I am building an app, which is going to have support for <code>FaceBook</code>.
  The problem is with login.If original <code>FaceBook</code> app is not installed on phone, 
  the login is going through custom dialog and everything works fine,
  but if official <code>FaceBook</code> app is installed, the login is going through custom dialog and 
  automatically redirect to original <code>FaceBook</code> app, and then nothing happened.
  I have tested this on different phones, and always was the same problem.Below is my code,</p>
  
  <pre><code>public class Login extends Activity {
  
  public static final String mAPP_ID = getString(R.string.APP_ID);
  public Facebook mFacebook = new Facebook(mAPP_ID);
  String cus_id, cus_mob, cus_name, cus_points, success,fb_id;
  SessionManager session;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      ((Button) findViewById(R.id.LoginButton)).setOnClickListener(loginButtonListener);
      SessionStore.restore(mFacebook, this);
  
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      mFacebook.authorizeCallback(requestCode, resultCode, data);
  }
  
  private OnClickListener loginButtonListener = new OnClickListener() {
      public void onClick(View v) {
          if (!mFacebook.isSessionValid()) {
              Toast.makeText(Login.this, "Authorizing", Toast.LENGTH_SHORT).show();
              mFacebook.authorize(Login.this, new String[] { "" },
                      new LoginDialogListener());
          } else {
              Toast.makeText(Login.this, "Has valid session",Toast.LENGTH_SHORT).show();
              try {
                  JSONObject json = Util.parseJson(mFacebook.request("me"));
                  String facebookID = json.getString("id");
                  String firstName = json.getString("first_name");
                  String lastName = json.getString("last_name");
                  Toast.makeText(
                          Login.this,
                          "You already have a valid session, " + firstName
                                  + " " + lastName
                                  + ". No need to re-authorize.",
                          Toast.LENGTH_SHORT).show();
  
                  Intent in = new Intent(getApplicationContext(),
                          Userpage1.class);
                  startActivity(in);
  
              } catch (Exception error) {
                  Toast.makeText(Login.this, error.toString(),
                          Toast.LENGTH_SHORT).show();
              } catch (FacebookError error) {
                  Toast.makeText(Login.this, error.toString(),
                          Toast.LENGTH_SHORT).show();
              }
          }
      }
  };
  
  public final class LoginDialogListener implements DialogListener {
      public void onComplete(Bundle values) {
          try {
              // The user has logged in, so now you can query and use their
              // Facebook info
              JSONObject json = Util.parseJson(mFacebook.request("me"));
              String facebookID = json.getString("id");
              String firstName = json.getString("first_name");
              String lastName = json.getString("last_name");
              Toast.makeText(
                      Login.this,
                      "Thank you for Logging In, " + firstName + " "
                              + lastName + "!", Toast.LENGTH_SHORT).show();
  
              SessionStore.save(mFacebook, Login.this);
  
              ArrayList&lt;NameValuePair&gt; postParameters = new ArrayList&lt;NameValuePair&gt;();
              postParameters.add(new BasicNameValuePair("fb_id", facebookID));
              String response = null;
              try {
                  response = LoginHttpClient
                          .executeHttpPost(
                                  "http://10.0.2.2/Upshot_Loyalty_Program/android_api/get_fb_id.php",
                                  postParameters);
                  JSONObject json1 = new JSONObject(response);
                  JSONArray jArray = json1.getJSONArray("customer");
                  for (int i = 0; i &lt; jArray.length(); i++) {
                      JSONObject json_data = jArray.getJSONObject(i);
                      success = json_data.getString("success");
                      cus_id = json_data.getString("cus_id");
                      cus_name = json_data.getString("cus_name");
                      cus_points = json_data.getString("cus_points");
                      // User_List.add(json_data.getString("cus_id"));
                  }
  
              } catch (Exception e) {
              }
              if (success.equals("1")) {
                  session = new SessionManager(getApplicationContext());
                  session.createLoginSessionRemMe(cus_id, cus_name,
                          cus_points);
                  Intent i = new Intent(getApplicationContext(),
                          Userpage1.class);
                  startActivity(i);
              } else {
                  Intent i = new Intent(getApplicationContext(),
                          Mobileno.class);
                  i.putExtra("fb_id", facebookID);
                  startActivity(i);
              }
          } catch (Exception error) {
              Toast.makeText(Login.this, error.toString(), Toast.LENGTH_SHORT)
                      .show();
          } catch (FacebookError error) {
              Toast.makeText(Login.this, error.toString(), Toast.LENGTH_SHORT)
                      .show();
          }
      }
  
      public void onFacebookError(FacebookError error) {
          Toast.makeText(Login.this,
                  "Something went wrong. Please try again.",
                  Toast.LENGTH_LONG).show();
      }
  
      public void onError(DialogError error) {
          Toast.makeText(Login.this,
                  "Something went wrong. Please try again.",
                  Toast.LENGTH_LONG).show();
      }
  
      public void onCancel() {
          Toast.makeText(Login.this,
                  "Something went wrong. Please try again.",
                  Toast.LENGTH_LONG).show();
      }
  }
  
        }
  </code></pre>