Facebook Integration in Libgdx - android

I'm trying to integrate Facebook login in my game but since now I couldn't achieve this.
i have followed the instructions in :
https://github.com/libgdx/libgdx/wiki/Interfacing-with-platform-specific-code
And created my interface and implemented it for Android project but still no success. When i call my loginFacebook function , it shows me a circular load screen and my game screen comes back.
public class AndroidFacebookAdapter implements FacebookIntegration {
private String name;
private Activity androidActivity;
public AndroidFacebookAdapter(Activity andAct) {
super();
this.name = "";
this.androidActivity = andAct ;
}
#Override
public void loginFacebook() {
Gdx.app.log("AndroidFacebookAdapter"," Facebook login starts");
//Session.openActiveSession(this, allowLoginUI, callback)
androidActivity.runOnUiThread(new Runnable() {
#Override
public void run() {
Gdx.app.log("AndroidFacebookAdapter"," runOnUiThread runs");
Session.openActiveSession(androidActivity, true, new Session.StatusCallback() {
// callback when session changes state
#Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
Gdx.app.log("AndroidFacebookAdapter"," session.isOpened returns true ");
// make request to the /me API
Request.newMeRequest(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
#Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
Gdx.app.log("AndroidFacebookAdapter"," Facebook Login Succefull");
name = user.getName();
}
}
}).executeAsync();
}
}
});
}
});
}
#Override
public String getName() {
return name;
}
}
In my Android project i send this interface to the core project .
andAdap = new AndroidFacebookAdapter(this);
initialize(new MyGdxGame(andAdap), config);
And i called it when screen is touched.
game.facebookIntegration.loginFacebook();
In logcat i see :
10-27 13:06:47.988: I/AndroidFacebookAdapter(16774): Facebook login starts
10-27 13:06:47.988: I/AndroidFacebookAdapter(16774): runOnUiThread runs
After i see a circular loading screen (nothing on screen just black) then my game screen comes back again . In which step i made a mistake ?
Thank you for your answers .
EDIT 1 : After realizing i was already signed in my facebook account , i logged out. Then tried again and it was working. It was opening the Facebook app to ask me for credentials but even i enter the right user name / password my "onCompleted" function is not called.
Edit 2 : Now my problem solved , thanks to the tutorial at http://blog.supercookie.co.uk/post/94802569132/facebook-integration-w-libgdx
I just needed to use UiLifecycleHelper class and its implementation. My interface implmenting class now.
public class AndroidFacebookAdapter implements FacebookIntegration {
private String name;
public AndroidLauncher androidActivity;
private final UiLifecycleHelper uiHelper;
public AndroidFacebookAdapter(Activity andAct) {
super();
this.name = "";
this.androidActivity = (AndroidLauncher) andAct ;
this.uiHelper = new UiLifecycleHelper(this.androidActivity, new Session.StatusCallback() {
#Override
public void call(Session session, SessionState sessionState, Exception e) {
}
});
}
private void loginFacebookImp() {
Gdx.app.log("AndroidFacebookAdapter"," Facebook login starts");
androidActivity.runOnUiThread(new Runnable()
{
#Override
public void run()
{
Gdx.app.log("AndroidFacebookAdapter"," runOnUiThread runs");
Session.openActiveSession(androidActivity, true, new Session.StatusCallback()
{
// callback when session changes state
#Override
public void call(Session session, SessionState state, Exception exception)
{
Gdx.app.log("AndroidFacebookAdapter"," openActiveSession call start");
if (session.isOpened())
{
Gdx.app.log("AndroidFacebookAdapter"," session.isOpened returns true ");
// make request to the /me API
Request.newMeRequest(session, new Request.GraphUserCallback()
{
// callback after Graph API response with user object
#Override
public void onCompleted(GraphUser user, Response response) {
Gdx.app.log("AndroidFacebookAdapter"," onCompleted start");
if (user != null) {
Gdx.app.log("AndroidFacebookAdapter"," Facebook Login Succesfull");
Gdx.app.log("AndroidFacebookAdapter"," Facebook name is " + user.getName());
name = user.getName();
}
else
{
Gdx.app.log("AndroidFacebookAdapter"," Facebook Login failed");
}
}
}).executeAsync();
}
else
{
Gdx.app.log("AndroidFacebookAdapter"," session.isOpened() is false");
}
}
});
}
});
}
private boolean isLoggedInImp()
{
return Session.getActiveSession() != null && Session.getActiveSession().isOpened();
}
#Override
public String getName() {
return name;
}
#Override
public void loginFacebook() {
loginFacebookImp();
}
public void onCreate(Bundle savedInstanceState) {
uiHelper.onCreate(savedInstanceState);
}
public void onResume() {
uiHelper.onResume();
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
uiHelper.onActivityResult(requestCode, resultCode, data);
}
public void onSaveInstanceState(Bundle outState) {
uiHelper.onSaveInstanceState(outState);
}
public void onPause() {
uiHelper.onPause();
}
public void onStop() {
uiHelper.onStop();
}
public void onDestroy() {
uiHelper.onDestroy();
}
#Override
public boolean isLoggedIn() {
return isLoggedInImp();
}
}

As in edit 2 , just add the UiLifecycleHelper android side interface implementing class. Then it is working as expected. For more explanation :
http://blog.supercookie.co.uk/post/94802569132/facebook-integration-w-libgdx

Related

Facebook login in fragment

I would like to use Facebook login in my App. I have just registred app and added SDK to project. However, I tried to follow the tutorial from documentation but nothing worked (I need to get ID and email from profile and send to to my server).
Fragment
public class LoginFragment extends Fragment {
#BindView(R.id.ivLogo) ImageView ivLogo;
#BindView(R.id.email) EditText edEmail;
#BindView(R.id.password) EditText edPassword;
#BindView(R.id.btnFbLogin) LoginButton btnFbLogin;
private CallbackManager callbackManager;
private AccessTokenTracker accessTokenTracker;
private ProfileTracker profileTracker;
String email, password, ID;
User user;
public LoginFragment() {
// Required empty public constructor
}
public static LoginFragment newInstance() {
LoginFragment fragment = new LoginFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
// App code
Log.i("success", "success");
}
#Override
public void onCancel() {
// App code
}
#Override
public void onError(FacebookException exception) {
// App code
}
});
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_login_screen, container, false);
ButterKnife.bind(this, view);
btnFbLogin.setReadPermissions("email");
btnFbLogin.setFragment(this);
// Callback registration
btnFbLogin.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
// App code
}
#Override
public void onCancel() {
// App code
}
#Override
public void onError(FacebookException exception) {
// App code
}
});
return view;
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
#Override
public void onResume() {
super.onResume();
((MainActivity) getActivity()).getSupportActionBar().hide();
}
private void FBcallback() {
FacebookCallback<LoginResult> callback = new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
Profile profile = Profile.getCurrentProfile();
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
try {
String email = object.getString("email");
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
#Override
public void onCancel() { }
#Override
public void onError(FacebookException e) { }
};
btnFbLogin.setReadPermissions("email");
btnFbLogin.registerCallback(callbackManager, callback);
}
private void loginEmail() {
FactoryAPI.getInstanceLogin().login("hardcoded mail", "hardcoded password").enqueue(new Callback<UserResponse>() {
#Override
public void onResponse(Call<UserResponse> call, Response<UserResponse> response) {
if (response.isSuccessful()) {
user = response.body().getUser();
startActivity();
} else {
Toast.makeText(getContext(), R.string.email_password_is_not_right, Toast.LENGTH_LONG).show();
}
}
#Override
public void onFailure(Call<UserResponse> call, Throwable t) {
}
});
}
private void loginFB() {
FactoryAPI.getServieFBlogin().loginFB(email, ID).enqueue(new Callback<UserResponse>() {
#Override
public void onResponse(Call<UserResponse> call, Response<UserResponse> response) {
if (response.isSuccessful()) {
user = response.body().getUser();
startActivity();
} else {
Toast.makeText(getContext(), "Something went wrong", Toast.LENGTH_LONG).show();
}
}
#Override
public void onFailure(Call<UserResponse> call, Throwable t) {
Log.e("error", "error");
}
});
}
public void getEmailPassword() {
email = edEmail.getText().toString();
password = edPassword.getText().toString();
if (email.isEmpty() || password.isEmpty()) {
Toast.makeText(getContext(), R.string.empty_properties, Toast.LENGTH_SHORT).show();
}
}
public static boolean emailValidation(CharSequence target) {
return !TextUtils.isEmpty(target) && Patterns.EMAIL_ADDRESS.matcher(target).matches();
}
public void startActivity() {
Intent intent = new Intent(getContext(), AccountActivity.class);
intent.putExtra("account", user);
startActivity(intent);
}
#Override
public void onActivityResult(int requestCode, int responseCode, Intent intent) {
super.onActivityResult(requestCode, responseCode, intent);
callbackManager.onActivityResult(requestCode, responseCode, intent);
}
#OnClick({R.id.sign_up_email, R.id.btnFbLogin})
public void onClick(View view) {
switch (view.getId()) {
case R.id.sign_up_email:
loginEmail();
case R.id.btnFbLogin:
break;
}
}
private void getProfile(Profile profile){
if(profile != null){
ID = profile.getId();
}
}
}
As your facebook login is in Fragment not in activity, so the
callback comes in onActivityResult() of Activity in which this fragment attached.
You can check this after override the onActivityResult() of your activity, and put a debug point there.
After you getting result in your activity onActivityResult() method, you can send it to your fragment's onActivityResult().
Hope this will help.
First of all if you are using LoginButton then you don't need to register with LoginManager. Here is the sample
//Using Facebook's LoginButton
//Register Callback
callbackManager = CallbackManager.Factory.create();
loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList("email")); //set permissions as public_profile, email, etc
loginButton.setFragment(this); //If you are using in a fragment
// Callback registration
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
// App code
}
#Override
public void onCancel() {
// App code
}
#Override
public void onError(FacebookException exception) {
// App code
}
});
Now with LoginManager when using Custom Button to login instead of FB's LoginButton
//To check if you are already logged In
boolean loggedIn = AccessToken.getCurrentAccessToken() == null;
// To Manually login. This will launch facebook's login screen.
LoginManager.getInstance().logInWithReadPermissions(this,
Arrays.asList("public_profile","email"));
In both the cases, for Fragment or Activity you need to handle onActivityResult
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
}

Facebook SDK LoginButton to custom Button Android

I want to integrate the Facebook login dialog into the activity. If a custom button is pressed, the app must login via Facebook (or autologin if the user and password were entered before).
I managed to do this by adding the LoginButton in the activity, but I want to override it's functionality. If the user clicks the button, the action behind LoginButton will be executed.
I need this because I want to verify first if the device has an active internet connection, but with my implementation the app tries to login with Facebook and after that the alert dialog with 'no internet connection' appears.
Here's my activity. Facebook login starts when I click the authButton, even no action is set in the onClickListener.
public class LoginActivity {
private Activity mActivity;
private User userR;
private static final String TAG = "Login";
private UiLifecycleHelper uiHelper;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mActivity = this;
LoginButton authButton = (LoginButton) findViewById(R.id.authButton1);
authButton.setReadPermissions(Arrays.asList("public_profile", "email"));
authButton.setOnClickListener(onClickListener);
authButton.setText("Connect with Facebook");
authButton.setBackgroundResource(R.drawable.button_facebook);
authButton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
uiHelper = new UiLifecycleHelper(mActivity, callback);
uiHelper.onCreate(savedInstanceState);
}
private OnClickListener onClickListener = new OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.authButton1:
break;
}
}
};
#Override
protected void onStart() {
super.onStart();
}
#Override
public void onBackPressed() {
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
}
private Session.StatusCallback callback = new Session.StatusCallback() {
#Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
#Override
public void onResume() {
super.onResume();
Session session = Session.getActiveSession();
if (session != null && (session.isOpened() || session.isClosed())) {
onSessionStateChange(session, session.getState(), null);
}
uiHelper.onResume();
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(mActivity, requestCode, resultCode, data);
userR = new User();
if (Session.getActiveSession().isOpened()) {
// Request user data and show the results
Request.newMeRequest(Session.getActiveSession(), new GraphUserCallback() {
#Override
public void onCompleted(GraphUser user, Response response) {
if (null != user) {
//getting email, name, gender
}
login();
}
}).executeAsync();
}
}
#Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
#Override
public void onDestroy() {
super.onDestroy();
Session.getActiveSession().closeAndClearTokenInformation();
uiHelper.onDestroy();
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
public void login() {
//login to server with data fetched from Graph user
}
Here is the XML for the LoginButton
com.facebook.widget.LoginButton
android:id="#+id/authButton1"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="30dp"
fb:login_text="Connect with Facebook"
fb:logout_text="Connect with Facebook"
The setOnClickListener on the LoginButton is overridden so you don't accidentally replace it, and instead proxies to the listener you set after login handling is done.
You should consider disabling or hiding the button altogether if there's no internet connection, rather than waiting until the user clicks on it.

Android get facebook username exception only the original thread that created a view hierarchy

i working facebook api in android. i successfully can sing in in facebook and try to check facebook user name
i wrote some code but i have
only the original thread that created a view hierarchy
exception
this is a my code:
public void LoginFacebook() {
mFacebook.authorize(this, mPermissions, new LoginDialogListener());
}
private final class LoginDialogListener implements DialogListener {
public void onComplete(Bundle values) {
SessionStore.save(mFacebook, getApplicationContext());
getProfileInformation();
}
public void onCancel() {
SessionEvents.onLoginError("Action Canceled");
}
#Override
public void onFacebookError(FacebookError error) {
SessionEvents.onLoginError(error.getMessage());
}
#Override
public void onError(DialogError error) {
SessionEvents.onLoginError(error.getMessage());
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mFacebook.authorizeCallback(requestCode, resultCode, data);
}
#SuppressWarnings("deprecation")
#SuppressLint("SdCardPath")
public void getProfileInformation() {
mAsyncRunner.request("me", new BaseRequestListener() {
#SuppressLint("CommitPrefEdits")
#Override
public void onComplete(String response, Object state) {
Log.e("Profile", response);
String json = response;
try {
JSONObject profile = new JSONObject(json);
facebook_userid = profile.getString("id");
facebook_username = profile.getString("name");
facebook_username = facebook_username.replace("%20", " ");
fb_name.setText(facebook_username);
} catch (JSONException e) {
e.printStackTrace();
}
}
#Override
public void onIOException(IOException e, Object state) {
}
#Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
}
#Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
}
#Override
public void onFacebookError(FacebookError e, Object state) {
}
});
}
what am i doing wrong. i can sing in but i can't to show username in textview.
if anyone knows solution please help me
thanks
In your onComplete method you're trying to set the text of a UI element. Your onComplete method is getting called from a background(non main/UI thread). Any time you make a UI change, it must be on the UI thread. Try inserting a runOnUIThread call in your onComplete like this:
runOnUiThread(new Runnable() {
public void run() {
fb_name.setText(facebook_username);
}
});
Note: you will need to make variables declared outside the runnable final (ex: facebook_username)
Also note: most (if not all) web based calls will return on a background thread so you might need to use runOnUIThread frequently.

NewPermissionsRequest Callback is not called

This is my code:
public class MainFragment extends Fragment implements OnClickListener {
private static final String EMAIL_PERMISSION = "email";
private static final String TAG = MainFragment.class.getSimpleName();
private UiLifecycleHelper uiHelper;
private LoginButton loginButton;
private GraphUser loggedInUser;
private TextView tvUserName, tvEmail;
private Button btnRequestEmail;
private Session mSession;
private Session.StatusCallback callback = new Session.StatusCallback() {
#Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.main, container, false);
tvUserName = (TextView) view.findViewById(R.id.tv_username);
tvEmail = (TextView) view.findViewById(R.id.tv_email);
btnRequestEmail = (Button) view.findViewById(R.id.btn_requestEmail);
btnRequestEmail.setOnClickListener(this);
loginButton = (LoginButton) view.findViewById(R.id.btn_login);
loginButton.setReadPermissions(Arrays.asList("public_profile"));
loginButton.setFragment(this);
loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
#Override
public void onUserInfoFetched(GraphUser user) {
loggedInUser = user;
updateUI();
}
});
return view;
}
#Override
public void onResume() {
super.onResume();
Session session = Session.getActiveSession();
if (session != null && (session.isOpened() || session.isClosed())) {
onSessionStateChange(session, session.getState(), null);
}
uiHelper.onResume();
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
#Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
#Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (session != null && session.isOpened()) {
mSession = session;
btnRequestEmail.setEnabled(true);
makeMeRequest(session);
}
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_requestEmail:
requestEmailPermissions();
break;
default:
break;
}
}
private void requestEmailPermissions() {
Session.NewPermissionsRequest newPermissionsRequest =
new Session.NewPermissionsRequest(getActivity(), Arrays.asList(EMAIL_PERMISSION));
newPermissionsRequest.setCallback(new StatusCallback() {
#Override
public void call(Session session, SessionState state, Exception exception) {
if(session.isPermissionGranted(EMAIL_PERMISSION)){
Toast.makeText(getActivity(), "Email permission granted :)", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getActivity(), "Email permission denied :(", Toast.LENGTH_LONG).show();
}
}
});
Session.getActiveSession().requestNewReadPermissions(newPermissionsRequest);
}
private void makeMeRequest(final Session session) {
Request request = Request.newMeRequest(session,
new GraphUserCallback() {
#Override
public void onCompleted(GraphUser user, Response response) {
if (session == Session.getActiveSession()) {
loggedInUser = user;
updateUI();
}
if (response.getError() != null) {
Log.e(TAG, response.getError().getErrorMessage());
}
}
});
request.executeAsync();
}
protected void updateUI() {
if (loggedInUser != null) {
tvUserName.setText(getString(R.string.welcome_user,
loggedInUser.getFirstName()));
if (loggedInUser.asMap().get(EMAIL_PERMISSION) != null) {
String email = loggedInUser.asMap().get(EMAIL_PERMISSION).toString();
tvEmail.setText(email);
}
} else {
tvUserName.setText("");
}
}
}
At first I login with the default facebook login button.
When the session is opened I enable the 'request email permission' button.
I request the email permission when the user clicks that button.
This works and I see the permission request screen, but I want to capture if the user doesn't accept the permission.
So I've added this callback to check if the permission is granted:
newPermissionsRequest.setCallback(new StatusCallback() {
#Override
public void call(Session session, SessionState state, Exception exception) {
if(session.isPermissionGranted(EMAIL_PERMISSION)){
Toast.makeText(getActivity(), "Email permission granted :)", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getActivity(), "Email permission denied :(", Toast.LENGTH_LONG).show();
}
}
});
But this callback is never called. How can I fix this?
PS: I'm using version 3.14.1 of the Facebook SDK
The correct activity's onActivityResult method must be called for your newPermissionRequest callback to run.
If the newPermissionRequest is happening in a fragment, make sure the activity's onActivityRequest call is passed to it by overriding onActivityRequest in your activity and then explicitly calling onActivityRequest in your fragment, something like this:
MyActivity.java:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
getSupportFragmentManager().findFragmentById(R.id.my_fragment_frame).onActivityResult(requestCode, resultCode, data);
}
onActivityResult can fail to be called if you have a mixture of static (xml) and dynamic (programmatic) fragments. For more information, please see this the accepted answer here: FB sdk, requestNewPublishPermissions() doesn't call any callback
In my case, my newPermissionRequest was attached to a different activity than I thought, so I was seeing onActivityResult getting called, but I didn't realize that it was the wrong activity.

facebook login takes long time during logging in

I have used facebook sdk 3.5 in android to create custom login button after clicking will get facebook details then send to server and then go to next intent(screen).I have created the code below and using it but the progress dialog takes long time to get to onCompletemethod() in facebook also sometime its timedOut.I have posted the code below please let me know if there is a better way to login than the one below and if I can reduce the time it takes to login facebook .I really appreciate ay help .Thanks in advance.
public class MainActivity extends Activity {
private ProgressDialog progressDialog;
static String email;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Wait...");
Button bt=(Button)findViewById(R.id.button1);
bt.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
runOnUiThread(new Runnable() {
#Override
public void run() {
progressDialog.show();
}
});
Session.openActiveSession(MainActivity.this, true, new Session.StatusCallback() {
// callback when session changes state
#Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
Request.newMeRequest(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
#Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
progressDialog.dismiss();
email= (String) response.getGraphObject().getProperty("email");
Log.d("email", email);
new FetchTask().execute();
}
}
}).executeAsync();
}
}
});
}});
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(Session.getActiveSession() != null)
{
Session.getActiveSession().onActivityResult(MainActivity.this, requestCode, resultCode, data);
}
}
I have the same issue. Maybe you found a solution.
I have the problem on Nexus 4 , but not get it on Samsung S3
Sorry I have no as much reputation to leave a comment.

Categories

Resources