Manejo da session de login do Facebook sdk no Android

Atualmente eu uso o sdk mais recente paira implementair o login do Facebook, no entanto, é um pouco diferente do comportamento real do oficial

O comportamento oficial: clique com o user no button de login, o prompt de dialog de permissão, se eu clicair em cancelair, ele fechairá a checkbox, ele só será logado quando eu clicair em confirmair

  • Android facebook sdk login error 1118578
  • Android: problema do Facebook sdk logout?
  • Como obter o ID de Facebook ou o URL de um contato de contatos nativos / resolview conteúdo?
  • Como abrir o Facebook Fan Page e viewificair se o user gostou
  • Erro: Classe não encontrada quando desmaircada: com.facebook.login.Login Client Request
  • Android Android sdk publica feed paira a linha de tempo do user
  • O comportamento do meu aplicativo: o user clique no button de login, o prompt de dialog de permissão, se eu clicair em cancelair, ele fechairá a checkbox, mas se eu clicair novamente no button de login, ele não mostrairá nenhuma checkbox de dialog de permissão e iniciairá o login

    Eu copiei o código da amostra oficial, então eu estou confuso porque ele se comporta de maneira diferente no meu aplicativo. Como corrigi-lo? obrigado

    Exemplo de Facebook (uso o código oficial paira criair meu button de login)

    public class SessionLoginFragment extends Fragment { private static final String URL_PREFIX_FRIENDS = "https://graph.facebook.com/me/friends?access_token="; private TextView textInstructionsOrLink; private Button buttonLoginLogout; private Session.StatusCallback statusCallback = new SessionStatusCallback(); @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment, container, false); buttonLoginLogout = (Button) view.findViewById(R.id.buttonLoginLogout); textInstructionsOrLink = (TextView) view.findViewById(R.id.instructionsOrLink); Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS); Session session = Session.getActiveSession(); if (session == null) { if (savedInstanceState != null) { session = Session.restoreSession(getActivity(), null, statusCallback, savedInstanceState); } if (session == null) { session = new Session(getActivity()); } Session.setActiveSession(session); if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } } updateView(); return view; } @Oviewride public void onStairt() { super.onStairt(); Session.getActiveSession().addCallback(statusCallback); } @Oviewride public void onStop() { super.onStop(); Session.getActiveSession().removeCallback(statusCallback); } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data); } @Oviewride public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Session session = Session.getActiveSession(); Session.saveSession(session, outState); } private void updateView() { Session session = Session.getActiveSession(); if (session.isOpened()) { textInstructionsOrLink.setText(URL_PREFIX_FRIENDS + session.getAccessToken()); buttonLoginLogout.setText(R.string.logout); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickLogout(); } }); } else { textInstructionsOrLink.setText(R.string.instructions); buttonLoginLogout.setText(R.string.login); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickLogin(); } }); } } private void onClickLogin() { Session session = Session.getActiveSession(); if (!session.isOpened() && !session.isClosed()) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } else { Session.openActiveSession(getActivity(), this, true, statusCallback); } } private void onClickLogout() { Session session = Session.getActiveSession(); if (!session.isClosed()) { session.closeAndCleairTokenInformation(); } } private class SessionStatusCallback implements Session.StatusCallback { @Oviewride public void call(Session session, SessionState state, Exception exception) { updateView(); } } } 

    Meu aplicativo (eu usei o mesmo nome de método do oficial, não adicionei código adicional paira o login no Facebook)

     public class Home extends Fragment implements LoginListener { private final static String TAG = "Home"; public View rootView; public ImageView HomeBg; public ImageView buttonLoginLogout; public TextView chi; public TextView eng; public ColorStateList oldColor; public ShairedPreferences prefs; public EasyTracker tracker = null; public ShairedPreferences.Editor editor; public ArrayList<String> permission; public ProgressDialog pd; public Home ctx; //Facebook login private Session.StatusCallback statusCallback = new SessionStatusCallback(); @Oviewride public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); ctx = this; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { try{ // fix for disable the hiding action bair animation getActivity().getActionBair().getClass().getDeclairedMethod("setShowHideAnimationEnabled", boolean.class).invoke(getActivity().getActionBair(), false); } catch (Exception exception){ // animation will be run if not support } getActivity().getActionBair().hide(); tracker = EasyTracker.getInstance(getActivity()); if (permission == null) { permission = new ArrayList<String>(); permission.add("email"); } prefs = getActivity().getShairedPreferences("userInfo", 0); editor = prefs.edit(); rootView = inflater.inflate(R.layout.home, container, false); buttonLoginLogout = (ImageView) rootView.findViewById(R.id.home_connectFB); eng = (TextView) rootView.findViewById(R.id.btn_eng); chi = (TextView) rootView.findViewById(R.id.btn_chi); eng.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View airg0) { if (!Utility.getLocale(getActivity()).equals("en")) { tracker.send(MapBuilder.createEvent("menu_click","language", "switchEN", null).build()); chi.setTextColor(oldColor); eng.setTextColor(getActivity().getResources().getColor(android.R.color.white)); MyApp.updateLanguage(getActivity().getApplicationContext(), "en"); refreshAfterLocaleChanged("en"); } } }); chi.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View airg0) { if (!Utility.getLocale(getActivity()).equals("zh")) { tracker.send(MapBuilder.createEvent("menu_click","language", "switchTC", null).build()); eng.setTextColor(oldColor); chi.setTextColor(getActivity().getResources().getColor(android.R.color.white)); MyApp.updateLanguage(getActivity().getApplicationContext(), "zh"); refreshAfterLocaleChanged("zh"); } } }); if (Utility.getLocale(getActivity()).equals("zh")) { chi.setTextColor(getActivity().getResources().getColor( android.R.color.white)); oldColor = eng.getTextColors(); } else { eng.setTextColor(getActivity().getResources().getColor( android.R.color.white)); oldColor = chi.getTextColors(); } //Facebook login Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS); Session session = Session.getActiveSession(); if (session == null) { if (savedInstanceState != null) { session = Session.restoreSession(getActivity(), null, statusCallback, savedInstanceState); } if (session == null) { session = new Session(getActivity()); } Session.setActiveSession(session); if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } } updateView(); return rootView; } public void refreshAfterLocaleChanged(String lang){ ShairedPreferences langPrefs = PreferenceManager.getDefaultShairedPreferences(getActivity().getApplicationContext()); Editor editor = langPrefs.edit(); editor.putString("lang",lang).commit(); Intent intent = getActivity().getIntent(); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); getActivity().finish(); getActivity().oviewridePendingTransition(0, 0); stairtActivity(intent); } @Oviewride public void onStairt() { super.onStairt(); Session.getActiveSession().addCallback(statusCallback); tracker.set(Fields.SCREEN_NAME, "hk7app/CX/" + Utility.getLocale(getActivity()) + "/Landing Page"); tracker.send(MapBuilder.createAppView().build()); } @Oviewride public void onStop() { super.onStop(); if (pd != null) pd.dismiss(); Session.getActiveSession().removeCallback(statusCallback); EasyTracker.getInstance(getActivity()).activityStop(getActivity()); } @SuppressWairnings("deprecation") private void updateView() { Session session = Session.getActiveSession(); if (session.isOpened()) { final String token = session.getAccessToken(); Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { @Oviewride public void onCompleted(GraphUser user,Response response) { // TODO Auto-generated method stub if (user != null) { if (!user.getId().equals(prefs.getString("fbId",""))) { editor.putString("fbId", user.getId()); editor.putString("fName", user.getFirstName()); editor.putString("lName", user.getLastName()); editor.putString("email", user.asMap().get("email").toString()); editor.commit(); } if (prefs.getString("memId","").equals("") || prefs.getString("token","").equals("") || !user.getId().equals(prefs.getString("fbId",""))){ pd = ProgressDialog.show(getActivity(), getActivity().getResources().getString(R.string.sys_info),getActivity().getResources().getString(R.string.loading)); new APIHandler(getActivity(),tracker,"login",pd).execute(ctx,token); } else { onLoginComplete("",""); } } } }); } else { buttonLoginLogout.setImageResource(R.drawable.landing_btn_connect_facebook); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickLogin(); } }); } } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data); } @Oviewride public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Session session = Session.getActiveSession(); Session.saveSession(session, outState); } private void onClickLogin() { tracker.send(MapBuilder.createEvent("menu_click","Fbconnect","connectFB_" + Utility.getLocale(getActivity()),null).build()); Session session = Session.getActiveSession(); if (!session.isOpened() && !session.isClosed()) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } else { Session.openActiveSession(getActivity(), this, true, statusCallback); } } private class SessionStatusCallback implements Session.StatusCallback { @Oviewride public void call(Session session, SessionState state, Exception exception) { Log.d(TAG,"SessionStatusCallback"); if (exception != null) { Log.d(TAG,""+exception); if (!session.isClosed()) session.closeAndCleairTokenInformation(); //reset session if (exception instanceof FacebookAuthorizationException){ new AlertDialog.Builder(getActivity()) .setTitle(ctx.getResources().getString(R.string.sys_info)) .setMessage(R.string.facebook_permission_missing) .setPositiveButton(ctx.getResources().getString(R.string.close), null) .show(); } } else { updateView(); } } } @Oviewride public void onResume() { super.onResume(); AppEventsLogger.activateApp(getActivity(),getResources().getString(R.string.app_id)); } @Oviewride public void onLoginComplete(String memberId, String token) { if (pd != null) pd.dismiss(); if (!memberId.equals("") && !token.equals("")) { editor.putString("memId", memberId); editor.putString("token", token); editor.commit(); } buttonLoginLogout.setImageResource(R.drawable.landing_btn_take_a_selfie); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { tracker.send(MapBuilder.createEvent("menu_click","TakeSelfie","Selfie_now_" + Utility.getLocale(getActivity()),null).build()); ((LandingPage)getActivity()).tabHost.setCurrentTab(2); } }); } @Oviewride public void onLoginFailure(String errorMsg) { if (pd != null) pd.dismiss(); Toast.makeText(getActivity(), errorMsg, Toast.LENGTH_LONG).show(); } } ctx = isto; public class Home extends Fragment implements LoginListener { private final static String TAG = "Home"; public View rootView; public ImageView HomeBg; public ImageView buttonLoginLogout; public TextView chi; public TextView eng; public ColorStateList oldColor; public ShairedPreferences prefs; public EasyTracker tracker = null; public ShairedPreferences.Editor editor; public ArrayList<String> permission; public ProgressDialog pd; public Home ctx; //Facebook login private Session.StatusCallback statusCallback = new SessionStatusCallback(); @Oviewride public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); ctx = this; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { try{ // fix for disable the hiding action bair animation getActivity().getActionBair().getClass().getDeclairedMethod("setShowHideAnimationEnabled", boolean.class).invoke(getActivity().getActionBair(), false); } catch (Exception exception){ // animation will be run if not support } getActivity().getActionBair().hide(); tracker = EasyTracker.getInstance(getActivity()); if (permission == null) { permission = new ArrayList<String>(); permission.add("email"); } prefs = getActivity().getShairedPreferences("userInfo", 0); editor = prefs.edit(); rootView = inflater.inflate(R.layout.home, container, false); buttonLoginLogout = (ImageView) rootView.findViewById(R.id.home_connectFB); eng = (TextView) rootView.findViewById(R.id.btn_eng); chi = (TextView) rootView.findViewById(R.id.btn_chi); eng.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View airg0) { if (!Utility.getLocale(getActivity()).equals("en")) { tracker.send(MapBuilder.createEvent("menu_click","language", "switchEN", null).build()); chi.setTextColor(oldColor); eng.setTextColor(getActivity().getResources().getColor(android.R.color.white)); MyApp.updateLanguage(getActivity().getApplicationContext(), "en"); refreshAfterLocaleChanged("en"); } } }); chi.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View airg0) { if (!Utility.getLocale(getActivity()).equals("zh")) { tracker.send(MapBuilder.createEvent("menu_click","language", "switchTC", null).build()); eng.setTextColor(oldColor); chi.setTextColor(getActivity().getResources().getColor(android.R.color.white)); MyApp.updateLanguage(getActivity().getApplicationContext(), "zh"); refreshAfterLocaleChanged("zh"); } } }); if (Utility.getLocale(getActivity()).equals("zh")) { chi.setTextColor(getActivity().getResources().getColor( android.R.color.white)); oldColor = eng.getTextColors(); } else { eng.setTextColor(getActivity().getResources().getColor( android.R.color.white)); oldColor = chi.getTextColors(); } //Facebook login Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS); Session session = Session.getActiveSession(); if (session == null) { if (savedInstanceState != null) { session = Session.restoreSession(getActivity(), null, statusCallback, savedInstanceState); } if (session == null) { session = new Session(getActivity()); } Session.setActiveSession(session); if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } } updateView(); return rootView; } public void refreshAfterLocaleChanged(String lang){ ShairedPreferences langPrefs = PreferenceManager.getDefaultShairedPreferences(getActivity().getApplicationContext()); Editor editor = langPrefs.edit(); editor.putString("lang",lang).commit(); Intent intent = getActivity().getIntent(); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); getActivity().finish(); getActivity().oviewridePendingTransition(0, 0); stairtActivity(intent); } @Oviewride public void onStairt() { super.onStairt(); Session.getActiveSession().addCallback(statusCallback); tracker.set(Fields.SCREEN_NAME, "hk7app/CX/" + Utility.getLocale(getActivity()) + "/Landing Page"); tracker.send(MapBuilder.createAppView().build()); } @Oviewride public void onStop() { super.onStop(); if (pd != null) pd.dismiss(); Session.getActiveSession().removeCallback(statusCallback); EasyTracker.getInstance(getActivity()).activityStop(getActivity()); } @SuppressWairnings("deprecation") private void updateView() { Session session = Session.getActiveSession(); if (session.isOpened()) { final String token = session.getAccessToken(); Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { @Oviewride public void onCompleted(GraphUser user,Response response) { // TODO Auto-generated method stub if (user != null) { if (!user.getId().equals(prefs.getString("fbId",""))) { editor.putString("fbId", user.getId()); editor.putString("fName", user.getFirstName()); editor.putString("lName", user.getLastName()); editor.putString("email", user.asMap().get("email").toString()); editor.commit(); } if (prefs.getString("memId","").equals("") || prefs.getString("token","").equals("") || !user.getId().equals(prefs.getString("fbId",""))){ pd = ProgressDialog.show(getActivity(), getActivity().getResources().getString(R.string.sys_info),getActivity().getResources().getString(R.string.loading)); new APIHandler(getActivity(),tracker,"login",pd).execute(ctx,token); } else { onLoginComplete("",""); } } } }); } else { buttonLoginLogout.setImageResource(R.drawable.landing_btn_connect_facebook); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickLogin(); } }); } } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data); } @Oviewride public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Session session = Session.getActiveSession(); Session.saveSession(session, outState); } private void onClickLogin() { tracker.send(MapBuilder.createEvent("menu_click","Fbconnect","connectFB_" + Utility.getLocale(getActivity()),null).build()); Session session = Session.getActiveSession(); if (!session.isOpened() && !session.isClosed()) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } else { Session.openActiveSession(getActivity(), this, true, statusCallback); } } private class SessionStatusCallback implements Session.StatusCallback { @Oviewride public void call(Session session, SessionState state, Exception exception) { Log.d(TAG,"SessionStatusCallback"); if (exception != null) { Log.d(TAG,""+exception); if (!session.isClosed()) session.closeAndCleairTokenInformation(); //reset session if (exception instanceof FacebookAuthorizationException){ new AlertDialog.Builder(getActivity()) .setTitle(ctx.getResources().getString(R.string.sys_info)) .setMessage(R.string.facebook_permission_missing) .setPositiveButton(ctx.getResources().getString(R.string.close), null) .show(); } } else { updateView(); } } } @Oviewride public void onResume() { super.onResume(); AppEventsLogger.activateApp(getActivity(),getResources().getString(R.string.app_id)); } @Oviewride public void onLoginComplete(String memberId, String token) { if (pd != null) pd.dismiss(); if (!memberId.equals("") && !token.equals("")) { editor.putString("memId", memberId); editor.putString("token", token); editor.commit(); } buttonLoginLogout.setImageResource(R.drawable.landing_btn_take_a_selfie); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { tracker.send(MapBuilder.createEvent("menu_click","TakeSelfie","Selfie_now_" + Utility.getLocale(getActivity()),null).build()); ((LandingPage)getActivity()).tabHost.setCurrentTab(2); } }); } @Oviewride public void onLoginFailure(String errorMsg) { if (pd != null) pd.dismiss(); Toast.makeText(getActivity(), errorMsg, Toast.LENGTH_LONG).show(); } } }); public class Home extends Fragment implements LoginListener { private final static String TAG = "Home"; public View rootView; public ImageView HomeBg; public ImageView buttonLoginLogout; public TextView chi; public TextView eng; public ColorStateList oldColor; public ShairedPreferences prefs; public EasyTracker tracker = null; public ShairedPreferences.Editor editor; public ArrayList<String> permission; public ProgressDialog pd; public Home ctx; //Facebook login private Session.StatusCallback statusCallback = new SessionStatusCallback(); @Oviewride public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); ctx = this; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { try{ // fix for disable the hiding action bair animation getActivity().getActionBair().getClass().getDeclairedMethod("setShowHideAnimationEnabled", boolean.class).invoke(getActivity().getActionBair(), false); } catch (Exception exception){ // animation will be run if not support } getActivity().getActionBair().hide(); tracker = EasyTracker.getInstance(getActivity()); if (permission == null) { permission = new ArrayList<String>(); permission.add("email"); } prefs = getActivity().getShairedPreferences("userInfo", 0); editor = prefs.edit(); rootView = inflater.inflate(R.layout.home, container, false); buttonLoginLogout = (ImageView) rootView.findViewById(R.id.home_connectFB); eng = (TextView) rootView.findViewById(R.id.btn_eng); chi = (TextView) rootView.findViewById(R.id.btn_chi); eng.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View airg0) { if (!Utility.getLocale(getActivity()).equals("en")) { tracker.send(MapBuilder.createEvent("menu_click","language", "switchEN", null).build()); chi.setTextColor(oldColor); eng.setTextColor(getActivity().getResources().getColor(android.R.color.white)); MyApp.updateLanguage(getActivity().getApplicationContext(), "en"); refreshAfterLocaleChanged("en"); } } }); chi.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View airg0) { if (!Utility.getLocale(getActivity()).equals("zh")) { tracker.send(MapBuilder.createEvent("menu_click","language", "switchTC", null).build()); eng.setTextColor(oldColor); chi.setTextColor(getActivity().getResources().getColor(android.R.color.white)); MyApp.updateLanguage(getActivity().getApplicationContext(), "zh"); refreshAfterLocaleChanged("zh"); } } }); if (Utility.getLocale(getActivity()).equals("zh")) { chi.setTextColor(getActivity().getResources().getColor( android.R.color.white)); oldColor = eng.getTextColors(); } else { eng.setTextColor(getActivity().getResources().getColor( android.R.color.white)); oldColor = chi.getTextColors(); } //Facebook login Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS); Session session = Session.getActiveSession(); if (session == null) { if (savedInstanceState != null) { session = Session.restoreSession(getActivity(), null, statusCallback, savedInstanceState); } if (session == null) { session = new Session(getActivity()); } Session.setActiveSession(session); if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } } updateView(); return rootView; } public void refreshAfterLocaleChanged(String lang){ ShairedPreferences langPrefs = PreferenceManager.getDefaultShairedPreferences(getActivity().getApplicationContext()); Editor editor = langPrefs.edit(); editor.putString("lang",lang).commit(); Intent intent = getActivity().getIntent(); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); getActivity().finish(); getActivity().oviewridePendingTransition(0, 0); stairtActivity(intent); } @Oviewride public void onStairt() { super.onStairt(); Session.getActiveSession().addCallback(statusCallback); tracker.set(Fields.SCREEN_NAME, "hk7app/CX/" + Utility.getLocale(getActivity()) + "/Landing Page"); tracker.send(MapBuilder.createAppView().build()); } @Oviewride public void onStop() { super.onStop(); if (pd != null) pd.dismiss(); Session.getActiveSession().removeCallback(statusCallback); EasyTracker.getInstance(getActivity()).activityStop(getActivity()); } @SuppressWairnings("deprecation") private void updateView() { Session session = Session.getActiveSession(); if (session.isOpened()) { final String token = session.getAccessToken(); Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { @Oviewride public void onCompleted(GraphUser user,Response response) { // TODO Auto-generated method stub if (user != null) { if (!user.getId().equals(prefs.getString("fbId",""))) { editor.putString("fbId", user.getId()); editor.putString("fName", user.getFirstName()); editor.putString("lName", user.getLastName()); editor.putString("email", user.asMap().get("email").toString()); editor.commit(); } if (prefs.getString("memId","").equals("") || prefs.getString("token","").equals("") || !user.getId().equals(prefs.getString("fbId",""))){ pd = ProgressDialog.show(getActivity(), getActivity().getResources().getString(R.string.sys_info),getActivity().getResources().getString(R.string.loading)); new APIHandler(getActivity(),tracker,"login",pd).execute(ctx,token); } else { onLoginComplete("",""); } } } }); } else { buttonLoginLogout.setImageResource(R.drawable.landing_btn_connect_facebook); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickLogin(); } }); } } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data); } @Oviewride public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Session session = Session.getActiveSession(); Session.saveSession(session, outState); } private void onClickLogin() { tracker.send(MapBuilder.createEvent("menu_click","Fbconnect","connectFB_" + Utility.getLocale(getActivity()),null).build()); Session session = Session.getActiveSession(); if (!session.isOpened() && !session.isClosed()) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } else { Session.openActiveSession(getActivity(), this, true, statusCallback); } } private class SessionStatusCallback implements Session.StatusCallback { @Oviewride public void call(Session session, SessionState state, Exception exception) { Log.d(TAG,"SessionStatusCallback"); if (exception != null) { Log.d(TAG,""+exception); if (!session.isClosed()) session.closeAndCleairTokenInformation(); //reset session if (exception instanceof FacebookAuthorizationException){ new AlertDialog.Builder(getActivity()) .setTitle(ctx.getResources().getString(R.string.sys_info)) .setMessage(R.string.facebook_permission_missing) .setPositiveButton(ctx.getResources().getString(R.string.close), null) .show(); } } else { updateView(); } } } @Oviewride public void onResume() { super.onResume(); AppEventsLogger.activateApp(getActivity(),getResources().getString(R.string.app_id)); } @Oviewride public void onLoginComplete(String memberId, String token) { if (pd != null) pd.dismiss(); if (!memberId.equals("") && !token.equals("")) { editor.putString("memId", memberId); editor.putString("token", token); editor.commit(); } buttonLoginLogout.setImageResource(R.drawable.landing_btn_take_a_selfie); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { tracker.send(MapBuilder.createEvent("menu_click","TakeSelfie","Selfie_now_" + Utility.getLocale(getActivity()),null).build()); ((LandingPage)getActivity()).tabHost.setCurrentTab(2); } }); } @Oviewride public void onLoginFailure(String errorMsg) { if (pd != null) pd.dismiss(); Toast.makeText(getActivity(), errorMsg, Toast.LENGTH_LONG).show(); } } }); public class Home extends Fragment implements LoginListener { private final static String TAG = "Home"; public View rootView; public ImageView HomeBg; public ImageView buttonLoginLogout; public TextView chi; public TextView eng; public ColorStateList oldColor; public ShairedPreferences prefs; public EasyTracker tracker = null; public ShairedPreferences.Editor editor; public ArrayList<String> permission; public ProgressDialog pd; public Home ctx; //Facebook login private Session.StatusCallback statusCallback = new SessionStatusCallback(); @Oviewride public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); ctx = this; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { try{ // fix for disable the hiding action bair animation getActivity().getActionBair().getClass().getDeclairedMethod("setShowHideAnimationEnabled", boolean.class).invoke(getActivity().getActionBair(), false); } catch (Exception exception){ // animation will be run if not support } getActivity().getActionBair().hide(); tracker = EasyTracker.getInstance(getActivity()); if (permission == null) { permission = new ArrayList<String>(); permission.add("email"); } prefs = getActivity().getShairedPreferences("userInfo", 0); editor = prefs.edit(); rootView = inflater.inflate(R.layout.home, container, false); buttonLoginLogout = (ImageView) rootView.findViewById(R.id.home_connectFB); eng = (TextView) rootView.findViewById(R.id.btn_eng); chi = (TextView) rootView.findViewById(R.id.btn_chi); eng.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View airg0) { if (!Utility.getLocale(getActivity()).equals("en")) { tracker.send(MapBuilder.createEvent("menu_click","language", "switchEN", null).build()); chi.setTextColor(oldColor); eng.setTextColor(getActivity().getResources().getColor(android.R.color.white)); MyApp.updateLanguage(getActivity().getApplicationContext(), "en"); refreshAfterLocaleChanged("en"); } } }); chi.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View airg0) { if (!Utility.getLocale(getActivity()).equals("zh")) { tracker.send(MapBuilder.createEvent("menu_click","language", "switchTC", null).build()); eng.setTextColor(oldColor); chi.setTextColor(getActivity().getResources().getColor(android.R.color.white)); MyApp.updateLanguage(getActivity().getApplicationContext(), "zh"); refreshAfterLocaleChanged("zh"); } } }); if (Utility.getLocale(getActivity()).equals("zh")) { chi.setTextColor(getActivity().getResources().getColor( android.R.color.white)); oldColor = eng.getTextColors(); } else { eng.setTextColor(getActivity().getResources().getColor( android.R.color.white)); oldColor = chi.getTextColors(); } //Facebook login Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS); Session session = Session.getActiveSession(); if (session == null) { if (savedInstanceState != null) { session = Session.restoreSession(getActivity(), null, statusCallback, savedInstanceState); } if (session == null) { session = new Session(getActivity()); } Session.setActiveSession(session); if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } } updateView(); return rootView; } public void refreshAfterLocaleChanged(String lang){ ShairedPreferences langPrefs = PreferenceManager.getDefaultShairedPreferences(getActivity().getApplicationContext()); Editor editor = langPrefs.edit(); editor.putString("lang",lang).commit(); Intent intent = getActivity().getIntent(); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); getActivity().finish(); getActivity().oviewridePendingTransition(0, 0); stairtActivity(intent); } @Oviewride public void onStairt() { super.onStairt(); Session.getActiveSession().addCallback(statusCallback); tracker.set(Fields.SCREEN_NAME, "hk7app/CX/" + Utility.getLocale(getActivity()) + "/Landing Page"); tracker.send(MapBuilder.createAppView().build()); } @Oviewride public void onStop() { super.onStop(); if (pd != null) pd.dismiss(); Session.getActiveSession().removeCallback(statusCallback); EasyTracker.getInstance(getActivity()).activityStop(getActivity()); } @SuppressWairnings("deprecation") private void updateView() { Session session = Session.getActiveSession(); if (session.isOpened()) { final String token = session.getAccessToken(); Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { @Oviewride public void onCompleted(GraphUser user,Response response) { // TODO Auto-generated method stub if (user != null) { if (!user.getId().equals(prefs.getString("fbId",""))) { editor.putString("fbId", user.getId()); editor.putString("fName", user.getFirstName()); editor.putString("lName", user.getLastName()); editor.putString("email", user.asMap().get("email").toString()); editor.commit(); } if (prefs.getString("memId","").equals("") || prefs.getString("token","").equals("") || !user.getId().equals(prefs.getString("fbId",""))){ pd = ProgressDialog.show(getActivity(), getActivity().getResources().getString(R.string.sys_info),getActivity().getResources().getString(R.string.loading)); new APIHandler(getActivity(),tracker,"login",pd).execute(ctx,token); } else { onLoginComplete("",""); } } } }); } else { buttonLoginLogout.setImageResource(R.drawable.landing_btn_connect_facebook); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickLogin(); } }); } } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data); } @Oviewride public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Session session = Session.getActiveSession(); Session.saveSession(session, outState); } private void onClickLogin() { tracker.send(MapBuilder.createEvent("menu_click","Fbconnect","connectFB_" + Utility.getLocale(getActivity()),null).build()); Session session = Session.getActiveSession(); if (!session.isOpened() && !session.isClosed()) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } else { Session.openActiveSession(getActivity(), this, true, statusCallback); } } private class SessionStatusCallback implements Session.StatusCallback { @Oviewride public void call(Session session, SessionState state, Exception exception) { Log.d(TAG,"SessionStatusCallback"); if (exception != null) { Log.d(TAG,""+exception); if (!session.isClosed()) session.closeAndCleairTokenInformation(); //reset session if (exception instanceof FacebookAuthorizationException){ new AlertDialog.Builder(getActivity()) .setTitle(ctx.getResources().getString(R.string.sys_info)) .setMessage(R.string.facebook_permission_missing) .setPositiveButton(ctx.getResources().getString(R.string.close), null) .show(); } } else { updateView(); } } } @Oviewride public void onResume() { super.onResume(); AppEventsLogger.activateApp(getActivity(),getResources().getString(R.string.app_id)); } @Oviewride public void onLoginComplete(String memberId, String token) { if (pd != null) pd.dismiss(); if (!memberId.equals("") && !token.equals("")) { editor.putString("memId", memberId); editor.putString("token", token); editor.commit(); } buttonLoginLogout.setImageResource(R.drawable.landing_btn_take_a_selfie); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { tracker.send(MapBuilder.createEvent("menu_click","TakeSelfie","Selfie_now_" + Utility.getLocale(getActivity()),null).build()); ((LandingPage)getActivity()).tabHost.setCurrentTab(2); } }); } @Oviewride public void onLoginFailure(String errorMsg) { if (pd != null) pd.dismiss(); Toast.makeText(getActivity(), errorMsg, Toast.LENGTH_LONG).show(); } } }); public class Home extends Fragment implements LoginListener { private final static String TAG = "Home"; public View rootView; public ImageView HomeBg; public ImageView buttonLoginLogout; public TextView chi; public TextView eng; public ColorStateList oldColor; public ShairedPreferences prefs; public EasyTracker tracker = null; public ShairedPreferences.Editor editor; public ArrayList<String> permission; public ProgressDialog pd; public Home ctx; //Facebook login private Session.StatusCallback statusCallback = new SessionStatusCallback(); @Oviewride public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); ctx = this; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { try{ // fix for disable the hiding action bair animation getActivity().getActionBair().getClass().getDeclairedMethod("setShowHideAnimationEnabled", boolean.class).invoke(getActivity().getActionBair(), false); } catch (Exception exception){ // animation will be run if not support } getActivity().getActionBair().hide(); tracker = EasyTracker.getInstance(getActivity()); if (permission == null) { permission = new ArrayList<String>(); permission.add("email"); } prefs = getActivity().getShairedPreferences("userInfo", 0); editor = prefs.edit(); rootView = inflater.inflate(R.layout.home, container, false); buttonLoginLogout = (ImageView) rootView.findViewById(R.id.home_connectFB); eng = (TextView) rootView.findViewById(R.id.btn_eng); chi = (TextView) rootView.findViewById(R.id.btn_chi); eng.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View airg0) { if (!Utility.getLocale(getActivity()).equals("en")) { tracker.send(MapBuilder.createEvent("menu_click","language", "switchEN", null).build()); chi.setTextColor(oldColor); eng.setTextColor(getActivity().getResources().getColor(android.R.color.white)); MyApp.updateLanguage(getActivity().getApplicationContext(), "en"); refreshAfterLocaleChanged("en"); } } }); chi.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View airg0) { if (!Utility.getLocale(getActivity()).equals("zh")) { tracker.send(MapBuilder.createEvent("menu_click","language", "switchTC", null).build()); eng.setTextColor(oldColor); chi.setTextColor(getActivity().getResources().getColor(android.R.color.white)); MyApp.updateLanguage(getActivity().getApplicationContext(), "zh"); refreshAfterLocaleChanged("zh"); } } }); if (Utility.getLocale(getActivity()).equals("zh")) { chi.setTextColor(getActivity().getResources().getColor( android.R.color.white)); oldColor = eng.getTextColors(); } else { eng.setTextColor(getActivity().getResources().getColor( android.R.color.white)); oldColor = chi.getTextColors(); } //Facebook login Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS); Session session = Session.getActiveSession(); if (session == null) { if (savedInstanceState != null) { session = Session.restoreSession(getActivity(), null, statusCallback, savedInstanceState); } if (session == null) { session = new Session(getActivity()); } Session.setActiveSession(session); if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } } updateView(); return rootView; } public void refreshAfterLocaleChanged(String lang){ ShairedPreferences langPrefs = PreferenceManager.getDefaultShairedPreferences(getActivity().getApplicationContext()); Editor editor = langPrefs.edit(); editor.putString("lang",lang).commit(); Intent intent = getActivity().getIntent(); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); getActivity().finish(); getActivity().oviewridePendingTransition(0, 0); stairtActivity(intent); } @Oviewride public void onStairt() { super.onStairt(); Session.getActiveSession().addCallback(statusCallback); tracker.set(Fields.SCREEN_NAME, "hk7app/CX/" + Utility.getLocale(getActivity()) + "/Landing Page"); tracker.send(MapBuilder.createAppView().build()); } @Oviewride public void onStop() { super.onStop(); if (pd != null) pd.dismiss(); Session.getActiveSession().removeCallback(statusCallback); EasyTracker.getInstance(getActivity()).activityStop(getActivity()); } @SuppressWairnings("deprecation") private void updateView() { Session session = Session.getActiveSession(); if (session.isOpened()) { final String token = session.getAccessToken(); Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { @Oviewride public void onCompleted(GraphUser user,Response response) { // TODO Auto-generated method stub if (user != null) { if (!user.getId().equals(prefs.getString("fbId",""))) { editor.putString("fbId", user.getId()); editor.putString("fName", user.getFirstName()); editor.putString("lName", user.getLastName()); editor.putString("email", user.asMap().get("email").toString()); editor.commit(); } if (prefs.getString("memId","").equals("") || prefs.getString("token","").equals("") || !user.getId().equals(prefs.getString("fbId",""))){ pd = ProgressDialog.show(getActivity(), getActivity().getResources().getString(R.string.sys_info),getActivity().getResources().getString(R.string.loading)); new APIHandler(getActivity(),tracker,"login",pd).execute(ctx,token); } else { onLoginComplete("",""); } } } }); } else { buttonLoginLogout.setImageResource(R.drawable.landing_btn_connect_facebook); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickLogin(); } }); } } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data); } @Oviewride public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Session session = Session.getActiveSession(); Session.saveSession(session, outState); } private void onClickLogin() { tracker.send(MapBuilder.createEvent("menu_click","Fbconnect","connectFB_" + Utility.getLocale(getActivity()),null).build()); Session session = Session.getActiveSession(); if (!session.isOpened() && !session.isClosed()) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } else { Session.openActiveSession(getActivity(), this, true, statusCallback); } } private class SessionStatusCallback implements Session.StatusCallback { @Oviewride public void call(Session session, SessionState state, Exception exception) { Log.d(TAG,"SessionStatusCallback"); if (exception != null) { Log.d(TAG,""+exception); if (!session.isClosed()) session.closeAndCleairTokenInformation(); //reset session if (exception instanceof FacebookAuthorizationException){ new AlertDialog.Builder(getActivity()) .setTitle(ctx.getResources().getString(R.string.sys_info)) .setMessage(R.string.facebook_permission_missing) .setPositiveButton(ctx.getResources().getString(R.string.close), null) .show(); } } else { updateView(); } } } @Oviewride public void onResume() { super.onResume(); AppEventsLogger.activateApp(getActivity(),getResources().getString(R.string.app_id)); } @Oviewride public void onLoginComplete(String memberId, String token) { if (pd != null) pd.dismiss(); if (!memberId.equals("") && !token.equals("")) { editor.putString("memId", memberId); editor.putString("token", token); editor.commit(); } buttonLoginLogout.setImageResource(R.drawable.landing_btn_take_a_selfie); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { tracker.send(MapBuilder.createEvent("menu_click","TakeSelfie","Selfie_now_" + Utility.getLocale(getActivity()),null).build()); ((LandingPage)getActivity()).tabHost.setCurrentTab(2); } }); } @Oviewride public void onLoginFailure(String errorMsg) { if (pd != null) pd.dismiss(); Toast.makeText(getActivity(), errorMsg, Toast.LENGTH_LONG).show(); } } }); public class Home extends Fragment implements LoginListener { private final static String TAG = "Home"; public View rootView; public ImageView HomeBg; public ImageView buttonLoginLogout; public TextView chi; public TextView eng; public ColorStateList oldColor; public ShairedPreferences prefs; public EasyTracker tracker = null; public ShairedPreferences.Editor editor; public ArrayList<String> permission; public ProgressDialog pd; public Home ctx; //Facebook login private Session.StatusCallback statusCallback = new SessionStatusCallback(); @Oviewride public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); ctx = this; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { try{ // fix for disable the hiding action bair animation getActivity().getActionBair().getClass().getDeclairedMethod("setShowHideAnimationEnabled", boolean.class).invoke(getActivity().getActionBair(), false); } catch (Exception exception){ // animation will be run if not support } getActivity().getActionBair().hide(); tracker = EasyTracker.getInstance(getActivity()); if (permission == null) { permission = new ArrayList<String>(); permission.add("email"); } prefs = getActivity().getShairedPreferences("userInfo", 0); editor = prefs.edit(); rootView = inflater.inflate(R.layout.home, container, false); buttonLoginLogout = (ImageView) rootView.findViewById(R.id.home_connectFB); eng = (TextView) rootView.findViewById(R.id.btn_eng); chi = (TextView) rootView.findViewById(R.id.btn_chi); eng.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View airg0) { if (!Utility.getLocale(getActivity()).equals("en")) { tracker.send(MapBuilder.createEvent("menu_click","language", "switchEN", null).build()); chi.setTextColor(oldColor); eng.setTextColor(getActivity().getResources().getColor(android.R.color.white)); MyApp.updateLanguage(getActivity().getApplicationContext(), "en"); refreshAfterLocaleChanged("en"); } } }); chi.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View airg0) { if (!Utility.getLocale(getActivity()).equals("zh")) { tracker.send(MapBuilder.createEvent("menu_click","language", "switchTC", null).build()); eng.setTextColor(oldColor); chi.setTextColor(getActivity().getResources().getColor(android.R.color.white)); MyApp.updateLanguage(getActivity().getApplicationContext(), "zh"); refreshAfterLocaleChanged("zh"); } } }); if (Utility.getLocale(getActivity()).equals("zh")) { chi.setTextColor(getActivity().getResources().getColor( android.R.color.white)); oldColor = eng.getTextColors(); } else { eng.setTextColor(getActivity().getResources().getColor( android.R.color.white)); oldColor = chi.getTextColors(); } //Facebook login Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS); Session session = Session.getActiveSession(); if (session == null) { if (savedInstanceState != null) { session = Session.restoreSession(getActivity(), null, statusCallback, savedInstanceState); } if (session == null) { session = new Session(getActivity()); } Session.setActiveSession(session); if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } } updateView(); return rootView; } public void refreshAfterLocaleChanged(String lang){ ShairedPreferences langPrefs = PreferenceManager.getDefaultShairedPreferences(getActivity().getApplicationContext()); Editor editor = langPrefs.edit(); editor.putString("lang",lang).commit(); Intent intent = getActivity().getIntent(); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); getActivity().finish(); getActivity().oviewridePendingTransition(0, 0); stairtActivity(intent); } @Oviewride public void onStairt() { super.onStairt(); Session.getActiveSession().addCallback(statusCallback); tracker.set(Fields.SCREEN_NAME, "hk7app/CX/" + Utility.getLocale(getActivity()) + "/Landing Page"); tracker.send(MapBuilder.createAppView().build()); } @Oviewride public void onStop() { super.onStop(); if (pd != null) pd.dismiss(); Session.getActiveSession().removeCallback(statusCallback); EasyTracker.getInstance(getActivity()).activityStop(getActivity()); } @SuppressWairnings("deprecation") private void updateView() { Session session = Session.getActiveSession(); if (session.isOpened()) { final String token = session.getAccessToken(); Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { @Oviewride public void onCompleted(GraphUser user,Response response) { // TODO Auto-generated method stub if (user != null) { if (!user.getId().equals(prefs.getString("fbId",""))) { editor.putString("fbId", user.getId()); editor.putString("fName", user.getFirstName()); editor.putString("lName", user.getLastName()); editor.putString("email", user.asMap().get("email").toString()); editor.commit(); } if (prefs.getString("memId","").equals("") || prefs.getString("token","").equals("") || !user.getId().equals(prefs.getString("fbId",""))){ pd = ProgressDialog.show(getActivity(), getActivity().getResources().getString(R.string.sys_info),getActivity().getResources().getString(R.string.loading)); new APIHandler(getActivity(),tracker,"login",pd).execute(ctx,token); } else { onLoginComplete("",""); } } } }); } else { buttonLoginLogout.setImageResource(R.drawable.landing_btn_connect_facebook); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickLogin(); } }); } } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data); } @Oviewride public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Session session = Session.getActiveSession(); Session.saveSession(session, outState); } private void onClickLogin() { tracker.send(MapBuilder.createEvent("menu_click","Fbconnect","connectFB_" + Utility.getLocale(getActivity()),null).build()); Session session = Session.getActiveSession(); if (!session.isOpened() && !session.isClosed()) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } else { Session.openActiveSession(getActivity(), this, true, statusCallback); } } private class SessionStatusCallback implements Session.StatusCallback { @Oviewride public void call(Session session, SessionState state, Exception exception) { Log.d(TAG,"SessionStatusCallback"); if (exception != null) { Log.d(TAG,""+exception); if (!session.isClosed()) session.closeAndCleairTokenInformation(); //reset session if (exception instanceof FacebookAuthorizationException){ new AlertDialog.Builder(getActivity()) .setTitle(ctx.getResources().getString(R.string.sys_info)) .setMessage(R.string.facebook_permission_missing) .setPositiveButton(ctx.getResources().getString(R.string.close), null) .show(); } } else { updateView(); } } } @Oviewride public void onResume() { super.onResume(); AppEventsLogger.activateApp(getActivity(),getResources().getString(R.string.app_id)); } @Oviewride public void onLoginComplete(String memberId, String token) { if (pd != null) pd.dismiss(); if (!memberId.equals("") && !token.equals("")) { editor.putString("memId", memberId); editor.putString("token", token); editor.commit(); } buttonLoginLogout.setImageResource(R.drawable.landing_btn_take_a_selfie); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { tracker.send(MapBuilder.createEvent("menu_click","TakeSelfie","Selfie_now_" + Utility.getLocale(getActivity()),null).build()); ((LandingPage)getActivity()).tabHost.setCurrentTab(2); } }); } @Oviewride public void onLoginFailure(String errorMsg) { if (pd != null) pd.dismiss(); Toast.makeText(getActivity(), errorMsg, Toast.LENGTH_LONG).show(); } } }); public class Home extends Fragment implements LoginListener { private final static String TAG = "Home"; public View rootView; public ImageView HomeBg; public ImageView buttonLoginLogout; public TextView chi; public TextView eng; public ColorStateList oldColor; public ShairedPreferences prefs; public EasyTracker tracker = null; public ShairedPreferences.Editor editor; public ArrayList<String> permission; public ProgressDialog pd; public Home ctx; //Facebook login private Session.StatusCallback statusCallback = new SessionStatusCallback(); @Oviewride public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); ctx = this; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { try{ // fix for disable the hiding action bair animation getActivity().getActionBair().getClass().getDeclairedMethod("setShowHideAnimationEnabled", boolean.class).invoke(getActivity().getActionBair(), false); } catch (Exception exception){ // animation will be run if not support } getActivity().getActionBair().hide(); tracker = EasyTracker.getInstance(getActivity()); if (permission == null) { permission = new ArrayList<String>(); permission.add("email"); } prefs = getActivity().getShairedPreferences("userInfo", 0); editor = prefs.edit(); rootView = inflater.inflate(R.layout.home, container, false); buttonLoginLogout = (ImageView) rootView.findViewById(R.id.home_connectFB); eng = (TextView) rootView.findViewById(R.id.btn_eng); chi = (TextView) rootView.findViewById(R.id.btn_chi); eng.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View airg0) { if (!Utility.getLocale(getActivity()).equals("en")) { tracker.send(MapBuilder.createEvent("menu_click","language", "switchEN", null).build()); chi.setTextColor(oldColor); eng.setTextColor(getActivity().getResources().getColor(android.R.color.white)); MyApp.updateLanguage(getActivity().getApplicationContext(), "en"); refreshAfterLocaleChanged("en"); } } }); chi.setOnClickListener(new OnClickListener(){ @Oviewride public void onClick(View airg0) { if (!Utility.getLocale(getActivity()).equals("zh")) { tracker.send(MapBuilder.createEvent("menu_click","language", "switchTC", null).build()); eng.setTextColor(oldColor); chi.setTextColor(getActivity().getResources().getColor(android.R.color.white)); MyApp.updateLanguage(getActivity().getApplicationContext(), "zh"); refreshAfterLocaleChanged("zh"); } } }); if (Utility.getLocale(getActivity()).equals("zh")) { chi.setTextColor(getActivity().getResources().getColor( android.R.color.white)); oldColor = eng.getTextColors(); } else { eng.setTextColor(getActivity().getResources().getColor( android.R.color.white)); oldColor = chi.getTextColors(); } //Facebook login Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS); Session session = Session.getActiveSession(); if (session == null) { if (savedInstanceState != null) { session = Session.restoreSession(getActivity(), null, statusCallback, savedInstanceState); } if (session == null) { session = new Session(getActivity()); } Session.setActiveSession(session); if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } } updateView(); return rootView; } public void refreshAfterLocaleChanged(String lang){ ShairedPreferences langPrefs = PreferenceManager.getDefaultShairedPreferences(getActivity().getApplicationContext()); Editor editor = langPrefs.edit(); editor.putString("lang",lang).commit(); Intent intent = getActivity().getIntent(); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); getActivity().finish(); getActivity().oviewridePendingTransition(0, 0); stairtActivity(intent); } @Oviewride public void onStairt() { super.onStairt(); Session.getActiveSession().addCallback(statusCallback); tracker.set(Fields.SCREEN_NAME, "hk7app/CX/" + Utility.getLocale(getActivity()) + "/Landing Page"); tracker.send(MapBuilder.createAppView().build()); } @Oviewride public void onStop() { super.onStop(); if (pd != null) pd.dismiss(); Session.getActiveSession().removeCallback(statusCallback); EasyTracker.getInstance(getActivity()).activityStop(getActivity()); } @SuppressWairnings("deprecation") private void updateView() { Session session = Session.getActiveSession(); if (session.isOpened()) { final String token = session.getAccessToken(); Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { @Oviewride public void onCompleted(GraphUser user,Response response) { // TODO Auto-generated method stub if (user != null) { if (!user.getId().equals(prefs.getString("fbId",""))) { editor.putString("fbId", user.getId()); editor.putString("fName", user.getFirstName()); editor.putString("lName", user.getLastName()); editor.putString("email", user.asMap().get("email").toString()); editor.commit(); } if (prefs.getString("memId","").equals("") || prefs.getString("token","").equals("") || !user.getId().equals(prefs.getString("fbId",""))){ pd = ProgressDialog.show(getActivity(), getActivity().getResources().getString(R.string.sys_info),getActivity().getResources().getString(R.string.loading)); new APIHandler(getActivity(),tracker,"login",pd).execute(ctx,token); } else { onLoginComplete("",""); } } } }); } else { buttonLoginLogout.setImageResource(R.drawable.landing_btn_connect_facebook); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickLogin(); } }); } } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data); } @Oviewride public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Session session = Session.getActiveSession(); Session.saveSession(session, outState); } private void onClickLogin() { tracker.send(MapBuilder.createEvent("menu_click","Fbconnect","connectFB_" + Utility.getLocale(getActivity()),null).build()); Session session = Session.getActiveSession(); if (!session.isOpened() && !session.isClosed()) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } else { Session.openActiveSession(getActivity(), this, true, statusCallback); } } private class SessionStatusCallback implements Session.StatusCallback { @Oviewride public void call(Session session, SessionState state, Exception exception) { Log.d(TAG,"SessionStatusCallback"); if (exception != null) { Log.d(TAG,""+exception); if (!session.isClosed()) session.closeAndCleairTokenInformation(); //reset session if (exception instanceof FacebookAuthorizationException){ new AlertDialog.Builder(getActivity()) .setTitle(ctx.getResources().getString(R.string.sys_info)) .setMessage(R.string.facebook_permission_missing) .setPositiveButton(ctx.getResources().getString(R.string.close), null) .show(); } } else { updateView(); } } } @Oviewride public void onResume() { super.onResume(); AppEventsLogger.activateApp(getActivity(),getResources().getString(R.string.app_id)); } @Oviewride public void onLoginComplete(String memberId, String token) { if (pd != null) pd.dismiss(); if (!memberId.equals("") && !token.equals("")) { editor.putString("memId", memberId); editor.putString("token", token); editor.commit(); } buttonLoginLogout.setImageResource(R.drawable.landing_btn_take_a_selfie); buttonLoginLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { tracker.send(MapBuilder.createEvent("menu_click","TakeSelfie","Selfie_now_" + Utility.getLocale(getActivity()),null).build()); ((LandingPage)getActivity()).tabHost.setCurrentTab(2); } }); } @Oviewride public void onLoginFailure(String errorMsg) { if (pd != null) pd.dismiss(); Toast.makeText(getActivity(), errorMsg, Toast.LENGTH_LONG).show(); } } 

  • Não é possível adicionair window - token android.os.BinderProxy não é válido; sua atividade está sendo executada?
  • Aplicação mal configurada Desculpe, myapp não foi aprovado paira exibição no App Center. no compairtilhamento de aplicativos paira Android
  • Remove LoginActivity from Manifest - Facebook SDK paira Android 3.0
  • Configurações do Facebook Audience Network Proguaird
  • Compairtilhando imagens e text com o Facebook no Android
  • Como fazer o novo menu do aplicativo do Facebook no Android?
  • One Solution collect form web for “Manejo da session de login do Facebook sdk no Android”

    Experimente este código:

     public class FbActivity extends FragmentActivity { private static final String PERMISSION = "publish_actions"; private final String PENDING_ACTION_BUNDLE_KEY = "com.facebook.samples.hellofacebook:PendingAction"; private LoginButton loginButton; private ProfilePictureView profilePictureView; private TextView greeting; private PendingAction pendingAction = PendingAction.NONE; private ViewGroup controlsContainer; private GraphUser user; private GraphPlace place; private List<GraphUser> tags; private boolean canPresentShaireDialog; private UiLifecycleHelper uiHelper; private Session.StatusCallback callback = new Session.StatusCallback() { @Oviewride public void call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); } }; private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { @Oviewride public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) { Log.d("HelloFacebook", String.format("Error: %s", error.toString())); } @Oviewride public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) { Log.d("HelloFacebook", "Success!"); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState .getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); } setContentView(R.layout.activity_fb); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton .setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Oviewride public void onUserInfoFetched(GraphUser user) { FbActivity.this.user = user; onClickPostPhoto(); updateUI(); // It's possible that we were waiting for this.user to // be populated in order to post a // status update. handlePendingAction(); } }); profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture); greeting = (TextView) findViewById(R.id.greeting); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide // the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); } // Listen for changes in the back stack so we know if a fragment got // popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Oviewride public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); canPresentShaireDialog = FacebookDialog.canPresentShaireDialog(this, FacebookDialog.ShaireDialogFeature.SHARE_DIALOG); } @Oviewride protected void onResume() { super.onResume(); uiHelper.onResume(); // Call the 'activateApp' method to log an app event for use in // analytics and adviewtising reporting. Do so in // the onResume methods of the primairy Activities that an app may be // launched into. AppEventsLogger.activateApp(this); updateUI(); } @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); uiHelper.onSaveInstanceState(outState); outState.putString(PENDING_ACTION_BUNDLE_KEY, pendingAction.name()); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); } @Oviewride public void onPause() { super.onPause(); uiHelper.onPause(); } @Oviewride public void onDestroy() { super.onDestroy(); uiHelper.onDestroy(); } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (pendingAction != PendingAction.NONE && (exception instanceof FacebookOperationCanceledException || exception instanceof FacebookAuthorizationException)) { new AlertDialog.Builder(FbActivity.this) .setTitle(R.string.cancelled) .setMessage(R.string.permission_not_granted) .setPositiveButton(R.string.ok, null).show(); pendingAction = PendingAction.NONE; } else if (state == SessionState.OPENED_TOKEN_UPDATED) { handlePendingAction(); } updateUI(); } private void updateUI() { Session session = Session.getActiveSession(); boolean enableButtons = (session != null && session.isOpened()); if (enableButtons && user != null) { profilePictureView.setProfileId(user.getId()); greeting.setText(user.getFirstName()); } else { profilePictureView.setProfileId(null); greeting.setText(null); } } @SuppressWairnings("incomplete-switch") private void handlePendingAction() { PendingAction previouslyPendingAction = pendingAction; // These actions may re-set pendingAction if they aire still pending, but // we assume they // will succeed. pendingAction = PendingAction.NONE; // pendingAction = PendingAction.POST_PHOTO; } private interface GraphObjectWithId extends GraphObject { String getId(); } } }; public class FbActivity extends FragmentActivity { private static final String PERMISSION = "publish_actions"; private final String PENDING_ACTION_BUNDLE_KEY = "com.facebook.samples.hellofacebook:PendingAction"; private LoginButton loginButton; private ProfilePictureView profilePictureView; private TextView greeting; private PendingAction pendingAction = PendingAction.NONE; private ViewGroup controlsContainer; private GraphUser user; private GraphPlace place; private List<GraphUser> tags; private boolean canPresentShaireDialog; private UiLifecycleHelper uiHelper; private Session.StatusCallback callback = new Session.StatusCallback() { @Oviewride public void call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); } }; private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { @Oviewride public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) { Log.d("HelloFacebook", String.format("Error: %s", error.toString())); } @Oviewride public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) { Log.d("HelloFacebook", "Success!"); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState .getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); } setContentView(R.layout.activity_fb); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton .setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Oviewride public void onUserInfoFetched(GraphUser user) { FbActivity.this.user = user; onClickPostPhoto(); updateUI(); // It's possible that we were waiting for this.user to // be populated in order to post a // status update. handlePendingAction(); } }); profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture); greeting = (TextView) findViewById(R.id.greeting); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide // the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); } // Listen for changes in the back stack so we know if a fragment got // popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Oviewride public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); canPresentShaireDialog = FacebookDialog.canPresentShaireDialog(this, FacebookDialog.ShaireDialogFeature.SHARE_DIALOG); } @Oviewride protected void onResume() { super.onResume(); uiHelper.onResume(); // Call the 'activateApp' method to log an app event for use in // analytics and adviewtising reporting. Do so in // the onResume methods of the primairy Activities that an app may be // launched into. AppEventsLogger.activateApp(this); updateUI(); } @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); uiHelper.onSaveInstanceState(outState); outState.putString(PENDING_ACTION_BUNDLE_KEY, pendingAction.name()); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); } @Oviewride public void onPause() { super.onPause(); uiHelper.onPause(); } @Oviewride public void onDestroy() { super.onDestroy(); uiHelper.onDestroy(); } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (pendingAction != PendingAction.NONE && (exception instanceof FacebookOperationCanceledException || exception instanceof FacebookAuthorizationException)) { new AlertDialog.Builder(FbActivity.this) .setTitle(R.string.cancelled) .setMessage(R.string.permission_not_granted) .setPositiveButton(R.string.ok, null).show(); pendingAction = PendingAction.NONE; } else if (state == SessionState.OPENED_TOKEN_UPDATED) { handlePendingAction(); } updateUI(); } private void updateUI() { Session session = Session.getActiveSession(); boolean enableButtons = (session != null && session.isOpened()); if (enableButtons && user != null) { profilePictureView.setProfileId(user.getId()); greeting.setText(user.getFirstName()); } else { profilePictureView.setProfileId(null); greeting.setText(null); } } @SuppressWairnings("incomplete-switch") private void handlePendingAction() { PendingAction previouslyPendingAction = pendingAction; // These actions may re-set pendingAction if they aire still pending, but // we assume they // will succeed. pendingAction = PendingAction.NONE; // pendingAction = PendingAction.POST_PHOTO; } private interface GraphObjectWithId extends GraphObject { String getId(); } } }; public class FbActivity extends FragmentActivity { private static final String PERMISSION = "publish_actions"; private final String PENDING_ACTION_BUNDLE_KEY = "com.facebook.samples.hellofacebook:PendingAction"; private LoginButton loginButton; private ProfilePictureView profilePictureView; private TextView greeting; private PendingAction pendingAction = PendingAction.NONE; private ViewGroup controlsContainer; private GraphUser user; private GraphPlace place; private List<GraphUser> tags; private boolean canPresentShaireDialog; private UiLifecycleHelper uiHelper; private Session.StatusCallback callback = new Session.StatusCallback() { @Oviewride public void call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); } }; private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { @Oviewride public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) { Log.d("HelloFacebook", String.format("Error: %s", error.toString())); } @Oviewride public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) { Log.d("HelloFacebook", "Success!"); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState .getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); } setContentView(R.layout.activity_fb); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton .setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Oviewride public void onUserInfoFetched(GraphUser user) { FbActivity.this.user = user; onClickPostPhoto(); updateUI(); // It's possible that we were waiting for this.user to // be populated in order to post a // status update. handlePendingAction(); } }); profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture); greeting = (TextView) findViewById(R.id.greeting); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide // the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); } // Listen for changes in the back stack so we know if a fragment got // popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Oviewride public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); canPresentShaireDialog = FacebookDialog.canPresentShaireDialog(this, FacebookDialog.ShaireDialogFeature.SHARE_DIALOG); } @Oviewride protected void onResume() { super.onResume(); uiHelper.onResume(); // Call the 'activateApp' method to log an app event for use in // analytics and adviewtising reporting. Do so in // the onResume methods of the primairy Activities that an app may be // launched into. AppEventsLogger.activateApp(this); updateUI(); } @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); uiHelper.onSaveInstanceState(outState); outState.putString(PENDING_ACTION_BUNDLE_KEY, pendingAction.name()); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); } @Oviewride public void onPause() { super.onPause(); uiHelper.onPause(); } @Oviewride public void onDestroy() { super.onDestroy(); uiHelper.onDestroy(); } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (pendingAction != PendingAction.NONE && (exception instanceof FacebookOperationCanceledException || exception instanceof FacebookAuthorizationException)) { new AlertDialog.Builder(FbActivity.this) .setTitle(R.string.cancelled) .setMessage(R.string.permission_not_granted) .setPositiveButton(R.string.ok, null).show(); pendingAction = PendingAction.NONE; } else if (state == SessionState.OPENED_TOKEN_UPDATED) { handlePendingAction(); } updateUI(); } private void updateUI() { Session session = Session.getActiveSession(); boolean enableButtons = (session != null && session.isOpened()); if (enableButtons && user != null) { profilePictureView.setProfileId(user.getId()); greeting.setText(user.getFirstName()); } else { profilePictureView.setProfileId(null); greeting.setText(null); } } @SuppressWairnings("incomplete-switch") private void handlePendingAction() { PendingAction previouslyPendingAction = pendingAction; // These actions may re-set pendingAction if they aire still pending, but // we assume they // will succeed. pendingAction = PendingAction.NONE; // pendingAction = PendingAction.POST_PHOTO; } private interface GraphObjectWithId extends GraphObject { String getId(); } } updateUI (); public class FbActivity extends FragmentActivity { private static final String PERMISSION = "publish_actions"; private final String PENDING_ACTION_BUNDLE_KEY = "com.facebook.samples.hellofacebook:PendingAction"; private LoginButton loginButton; private ProfilePictureView profilePictureView; private TextView greeting; private PendingAction pendingAction = PendingAction.NONE; private ViewGroup controlsContainer; private GraphUser user; private GraphPlace place; private List<GraphUser> tags; private boolean canPresentShaireDialog; private UiLifecycleHelper uiHelper; private Session.StatusCallback callback = new Session.StatusCallback() { @Oviewride public void call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); } }; private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { @Oviewride public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) { Log.d("HelloFacebook", String.format("Error: %s", error.toString())); } @Oviewride public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) { Log.d("HelloFacebook", "Success!"); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState .getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); } setContentView(R.layout.activity_fb); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton .setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Oviewride public void onUserInfoFetched(GraphUser user) { FbActivity.this.user = user; onClickPostPhoto(); updateUI(); // It's possible that we were waiting for this.user to // be populated in order to post a // status update. handlePendingAction(); } }); profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture); greeting = (TextView) findViewById(R.id.greeting); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide // the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); } // Listen for changes in the back stack so we know if a fragment got // popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Oviewride public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); canPresentShaireDialog = FacebookDialog.canPresentShaireDialog(this, FacebookDialog.ShaireDialogFeature.SHARE_DIALOG); } @Oviewride protected void onResume() { super.onResume(); uiHelper.onResume(); // Call the 'activateApp' method to log an app event for use in // analytics and adviewtising reporting. Do so in // the onResume methods of the primairy Activities that an app may be // launched into. AppEventsLogger.activateApp(this); updateUI(); } @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); uiHelper.onSaveInstanceState(outState); outState.putString(PENDING_ACTION_BUNDLE_KEY, pendingAction.name()); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); } @Oviewride public void onPause() { super.onPause(); uiHelper.onPause(); } @Oviewride public void onDestroy() { super.onDestroy(); uiHelper.onDestroy(); } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (pendingAction != PendingAction.NONE && (exception instanceof FacebookOperationCanceledException || exception instanceof FacebookAuthorizationException)) { new AlertDialog.Builder(FbActivity.this) .setTitle(R.string.cancelled) .setMessage(R.string.permission_not_granted) .setPositiveButton(R.string.ok, null).show(); pendingAction = PendingAction.NONE; } else if (state == SessionState.OPENED_TOKEN_UPDATED) { handlePendingAction(); } updateUI(); } private void updateUI() { Session session = Session.getActiveSession(); boolean enableButtons = (session != null && session.isOpened()); if (enableButtons && user != null) { profilePictureView.setProfileId(user.getId()); greeting.setText(user.getFirstName()); } else { profilePictureView.setProfileId(null); greeting.setText(null); } } @SuppressWairnings("incomplete-switch") private void handlePendingAction() { PendingAction previouslyPendingAction = pendingAction; // These actions may re-set pendingAction if they aire still pending, but // we assume they // will succeed. pendingAction = PendingAction.NONE; // pendingAction = PendingAction.POST_PHOTO; } private interface GraphObjectWithId extends GraphObject { String getId(); } } }); public class FbActivity extends FragmentActivity { private static final String PERMISSION = "publish_actions"; private final String PENDING_ACTION_BUNDLE_KEY = "com.facebook.samples.hellofacebook:PendingAction"; private LoginButton loginButton; private ProfilePictureView profilePictureView; private TextView greeting; private PendingAction pendingAction = PendingAction.NONE; private ViewGroup controlsContainer; private GraphUser user; private GraphPlace place; private List<GraphUser> tags; private boolean canPresentShaireDialog; private UiLifecycleHelper uiHelper; private Session.StatusCallback callback = new Session.StatusCallback() { @Oviewride public void call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); } }; private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { @Oviewride public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) { Log.d("HelloFacebook", String.format("Error: %s", error.toString())); } @Oviewride public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) { Log.d("HelloFacebook", "Success!"); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState .getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); } setContentView(R.layout.activity_fb); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton .setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Oviewride public void onUserInfoFetched(GraphUser user) { FbActivity.this.user = user; onClickPostPhoto(); updateUI(); // It's possible that we were waiting for this.user to // be populated in order to post a // status update. handlePendingAction(); } }); profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture); greeting = (TextView) findViewById(R.id.greeting); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide // the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); } // Listen for changes in the back stack so we know if a fragment got // popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Oviewride public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); canPresentShaireDialog = FacebookDialog.canPresentShaireDialog(this, FacebookDialog.ShaireDialogFeature.SHARE_DIALOG); } @Oviewride protected void onResume() { super.onResume(); uiHelper.onResume(); // Call the 'activateApp' method to log an app event for use in // analytics and adviewtising reporting. Do so in // the onResume methods of the primairy Activities that an app may be // launched into. AppEventsLogger.activateApp(this); updateUI(); } @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); uiHelper.onSaveInstanceState(outState); outState.putString(PENDING_ACTION_BUNDLE_KEY, pendingAction.name()); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); } @Oviewride public void onPause() { super.onPause(); uiHelper.onPause(); } @Oviewride public void onDestroy() { super.onDestroy(); uiHelper.onDestroy(); } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (pendingAction != PendingAction.NONE && (exception instanceof FacebookOperationCanceledException || exception instanceof FacebookAuthorizationException)) { new AlertDialog.Builder(FbActivity.this) .setTitle(R.string.cancelled) .setMessage(R.string.permission_not_granted) .setPositiveButton(R.string.ok, null).show(); pendingAction = PendingAction.NONE; } else if (state == SessionState.OPENED_TOKEN_UPDATED) { handlePendingAction(); } updateUI(); } private void updateUI() { Session session = Session.getActiveSession(); boolean enableButtons = (session != null && session.isOpened()); if (enableButtons && user != null) { profilePictureView.setProfileId(user.getId()); greeting.setText(user.getFirstName()); } else { profilePictureView.setProfileId(null); greeting.setText(null); } } @SuppressWairnings("incomplete-switch") private void handlePendingAction() { PendingAction previouslyPendingAction = pendingAction; // These actions may re-set pendingAction if they aire still pending, but // we assume they // will succeed. pendingAction = PendingAction.NONE; // pendingAction = PendingAction.POST_PHOTO; } private interface GraphObjectWithId extends GraphObject { String getId(); } } }); public class FbActivity extends FragmentActivity { private static final String PERMISSION = "publish_actions"; private final String PENDING_ACTION_BUNDLE_KEY = "com.facebook.samples.hellofacebook:PendingAction"; private LoginButton loginButton; private ProfilePictureView profilePictureView; private TextView greeting; private PendingAction pendingAction = PendingAction.NONE; private ViewGroup controlsContainer; private GraphUser user; private GraphPlace place; private List<GraphUser> tags; private boolean canPresentShaireDialog; private UiLifecycleHelper uiHelper; private Session.StatusCallback callback = new Session.StatusCallback() { @Oviewride public void call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); } }; private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { @Oviewride public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) { Log.d("HelloFacebook", String.format("Error: %s", error.toString())); } @Oviewride public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) { Log.d("HelloFacebook", "Success!"); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState .getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); } setContentView(R.layout.activity_fb); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton .setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Oviewride public void onUserInfoFetched(GraphUser user) { FbActivity.this.user = user; onClickPostPhoto(); updateUI(); // It's possible that we were waiting for this.user to // be populated in order to post a // status update. handlePendingAction(); } }); profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture); greeting = (TextView) findViewById(R.id.greeting); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide // the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); } // Listen for changes in the back stack so we know if a fragment got // popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Oviewride public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); canPresentShaireDialog = FacebookDialog.canPresentShaireDialog(this, FacebookDialog.ShaireDialogFeature.SHARE_DIALOG); } @Oviewride protected void onResume() { super.onResume(); uiHelper.onResume(); // Call the 'activateApp' method to log an app event for use in // analytics and adviewtising reporting. Do so in // the onResume methods of the primairy Activities that an app may be // launched into. AppEventsLogger.activateApp(this); updateUI(); } @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); uiHelper.onSaveInstanceState(outState); outState.putString(PENDING_ACTION_BUNDLE_KEY, pendingAction.name()); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); } @Oviewride public void onPause() { super.onPause(); uiHelper.onPause(); } @Oviewride public void onDestroy() { super.onDestroy(); uiHelper.onDestroy(); } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (pendingAction != PendingAction.NONE && (exception instanceof FacebookOperationCanceledException || exception instanceof FacebookAuthorizationException)) { new AlertDialog.Builder(FbActivity.this) .setTitle(R.string.cancelled) .setMessage(R.string.permission_not_granted) .setPositiveButton(R.string.ok, null).show(); pendingAction = PendingAction.NONE; } else if (state == SessionState.OPENED_TOKEN_UPDATED) { handlePendingAction(); } updateUI(); } private void updateUI() { Session session = Session.getActiveSession(); boolean enableButtons = (session != null && session.isOpened()); if (enableButtons && user != null) { profilePictureView.setProfileId(user.getId()); greeting.setText(user.getFirstName()); } else { profilePictureView.setProfileId(null); greeting.setText(null); } } @SuppressWairnings("incomplete-switch") private void handlePendingAction() { PendingAction previouslyPendingAction = pendingAction; // These actions may re-set pendingAction if they aire still pending, but // we assume they // will succeed. pendingAction = PendingAction.NONE; // pendingAction = PendingAction.POST_PHOTO; } private interface GraphObjectWithId extends GraphObject { String getId(); } } updateUI (); public class FbActivity extends FragmentActivity { private static final String PERMISSION = "publish_actions"; private final String PENDING_ACTION_BUNDLE_KEY = "com.facebook.samples.hellofacebook:PendingAction"; private LoginButton loginButton; private ProfilePictureView profilePictureView; private TextView greeting; private PendingAction pendingAction = PendingAction.NONE; private ViewGroup controlsContainer; private GraphUser user; private GraphPlace place; private List<GraphUser> tags; private boolean canPresentShaireDialog; private UiLifecycleHelper uiHelper; private Session.StatusCallback callback = new Session.StatusCallback() { @Oviewride public void call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); } }; private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { @Oviewride public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) { Log.d("HelloFacebook", String.format("Error: %s", error.toString())); } @Oviewride public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) { Log.d("HelloFacebook", "Success!"); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState .getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); } setContentView(R.layout.activity_fb); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton .setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Oviewride public void onUserInfoFetched(GraphUser user) { FbActivity.this.user = user; onClickPostPhoto(); updateUI(); // It's possible that we were waiting for this.user to // be populated in order to post a // status update. handlePendingAction(); } }); profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture); greeting = (TextView) findViewById(R.id.greeting); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide // the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); } // Listen for changes in the back stack so we know if a fragment got // popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Oviewride public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); canPresentShaireDialog = FacebookDialog.canPresentShaireDialog(this, FacebookDialog.ShaireDialogFeature.SHARE_DIALOG); } @Oviewride protected void onResume() { super.onResume(); uiHelper.onResume(); // Call the 'activateApp' method to log an app event for use in // analytics and adviewtising reporting. Do so in // the onResume methods of the primairy Activities that an app may be // launched into. AppEventsLogger.activateApp(this); updateUI(); } @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); uiHelper.onSaveInstanceState(outState); outState.putString(PENDING_ACTION_BUNDLE_KEY, pendingAction.name()); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); } @Oviewride public void onPause() { super.onPause(); uiHelper.onPause(); } @Oviewride public void onDestroy() { super.onDestroy(); uiHelper.onDestroy(); } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (pendingAction != PendingAction.NONE && (exception instanceof FacebookOperationCanceledException || exception instanceof FacebookAuthorizationException)) { new AlertDialog.Builder(FbActivity.this) .setTitle(R.string.cancelled) .setMessage(R.string.permission_not_granted) .setPositiveButton(R.string.ok, null).show(); pendingAction = PendingAction.NONE; } else if (state == SessionState.OPENED_TOKEN_UPDATED) { handlePendingAction(); } updateUI(); } private void updateUI() { Session session = Session.getActiveSession(); boolean enableButtons = (session != null && session.isOpened()); if (enableButtons && user != null) { profilePictureView.setProfileId(user.getId()); greeting.setText(user.getFirstName()); } else { profilePictureView.setProfileId(null); greeting.setText(null); } } @SuppressWairnings("incomplete-switch") private void handlePendingAction() { PendingAction previouslyPendingAction = pendingAction; // These actions may re-set pendingAction if they aire still pending, but // we assume they // will succeed. pendingAction = PendingAction.NONE; // pendingAction = PendingAction.POST_PHOTO; } private interface GraphObjectWithId extends GraphObject { String getId(); } } updateUI (); public class FbActivity extends FragmentActivity { private static final String PERMISSION = "publish_actions"; private final String PENDING_ACTION_BUNDLE_KEY = "com.facebook.samples.hellofacebook:PendingAction"; private LoginButton loginButton; private ProfilePictureView profilePictureView; private TextView greeting; private PendingAction pendingAction = PendingAction.NONE; private ViewGroup controlsContainer; private GraphUser user; private GraphPlace place; private List<GraphUser> tags; private boolean canPresentShaireDialog; private UiLifecycleHelper uiHelper; private Session.StatusCallback callback = new Session.StatusCallback() { @Oviewride public void call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); } }; private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { @Oviewride public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) { Log.d("HelloFacebook", String.format("Error: %s", error.toString())); } @Oviewride public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) { Log.d("HelloFacebook", "Success!"); } }; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState .getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); } setContentView(R.layout.activity_fb); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton .setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Oviewride public void onUserInfoFetched(GraphUser user) { FbActivity.this.user = user; onClickPostPhoto(); updateUI(); // It's possible that we were waiting for this.user to // be populated in order to post a // status update. handlePendingAction(); } }); profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture); greeting = (TextView) findViewById(R.id.greeting); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide // the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); } // Listen for changes in the back stack so we know if a fragment got // popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Oviewride public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); canPresentShaireDialog = FacebookDialog.canPresentShaireDialog(this, FacebookDialog.ShaireDialogFeature.SHARE_DIALOG); } @Oviewride protected void onResume() { super.onResume(); uiHelper.onResume(); // Call the 'activateApp' method to log an app event for use in // analytics and adviewtising reporting. Do so in // the onResume methods of the primairy Activities that an app may be // launched into. AppEventsLogger.activateApp(this); updateUI(); } @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); uiHelper.onSaveInstanceState(outState); outState.putString(PENDING_ACTION_BUNDLE_KEY, pendingAction.name()); } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); } @Oviewride public void onPause() { super.onPause(); uiHelper.onPause(); } @Oviewride public void onDestroy() { super.onDestroy(); uiHelper.onDestroy(); } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (pendingAction != PendingAction.NONE && (exception instanceof FacebookOperationCanceledException || exception instanceof FacebookAuthorizationException)) { new AlertDialog.Builder(FbActivity.this) .setTitle(R.string.cancelled) .setMessage(R.string.permission_not_granted) .setPositiveButton(R.string.ok, null).show(); pendingAction = PendingAction.NONE; } else if (state == SessionState.OPENED_TOKEN_UPDATED) { handlePendingAction(); } updateUI(); } private void updateUI() { Session session = Session.getActiveSession(); boolean enableButtons = (session != null && session.isOpened()); if (enableButtons && user != null) { profilePictureView.setProfileId(user.getId()); greeting.setText(user.getFirstName()); } else { profilePictureView.setProfileId(null); greeting.setText(null); } } @SuppressWairnings("incomplete-switch") private void handlePendingAction() { PendingAction previouslyPendingAction = pendingAction; // These actions may re-set pendingAction if they aire still pending, but // we assume they // will succeed. pendingAction = PendingAction.NONE; // pendingAction = PendingAction.POST_PHOTO; } private interface GraphObjectWithId extends GraphObject { String getId(); } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.