To make it work for API level 10 and higher i just employed and AsyncTask and it Worked!!
Use the below code:
//make this global declaration
private Facebook mFacebook;
private class FbLoginAsync extends AsyncTask<Void, Void, User> {
@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(ConstantsCtc.DIALOG_PROGRESS);
}
@Override
protected User doInBackground(Void... params) {
// facebooklogin();
return getFacebookData();
}
@Override
protected void onPostExecute(User u) {
super.onPostExecute(u);
// your facebook information is in User bean 'u'.
}
}
public User getFacebookData() {
User u = new User();
try {
JSONObject jsonME = null;
JSONObject jsonfrnd = null;
try {
jsonME = Util.parseJson(mFacebook.request("me"));
// jsonfrnd =
// Util.parseJson(mFacebook
// .request("me/friends"));
} catch (FacebookError e) {
e.printStackTrace();
u = null;
}
Log.w("fbjsonMe", " *\n " + jsonME);
// Log.e("fbjsonfrnds", " *\n " + jsonfrnd);
String mUserId = jsonME.getString("id");
String mUserName = jsonME.getString("first_name");
String mUseremail = jsonME.getString("email");
String birthday = jsonME.getString("birthday");
String gender = jsonME.getString("gender");
String full_name = jsonME.getString("name");
// Log.w("UserName", mUserName + " * " + mUseremail + " *\n "
// + jsonME);
// calculate age
String ag[] = birthday.split("/");
int y = Integer.parseInt(ag[2]);// get birth year
final Calendar cal = Calendar.getInstance();
int currentyear = cal.get(Calendar.YEAR);
int age = currentyear - y;
if (gender.equalsIgnoreCase("male"))
gender = "0";
else
gender = "1";
u.setUserId(mUserId);
u.setUserFullName(full_name);
u.setEmail(mUseremail);
u.setAge(age + "");
u.setGender(gender);
} catch (Exception e) {
e.printStackTrace();
u = null;
}
return u;
}
// then make a call to below method form your activity's button click or
// else
public void facebookLogin() {
this.mFacebook = new Facebook(appId);// give your appId
if (mFacebook.isSessionValid()) {
new FbLoginAsync().execute();
} else {
SessionEvents.AuthListener listener = new SessionEvents.AuthListener() {
@Override
public void onAuthSucceed() {
new FbLoginAsync().execute();
}
@Override
public void onAuthFail(String error) {
showDialogCustome("Error in Facebook Login, please try again later");
Log.e("onAuthFail", "onAuthFail");
}
};
SessionEvents.addAuthListener(listener);
mFacebook.authorize(this.activity, this.permissions,
Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
}
}
I hope this solves your problem. let me know