如何避免在Android Facebook SDK中显示已经授权的应用程序对话框

前端之家收集整理的这篇文章主要介绍了如何避免在Android Facebook SDK中显示已经授权的应用程序对话框前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我使用Facebook的 Android SDK单点登录时,我得到一个完全无用的页面.
  1. "You have already authorized app. Press "Okay" to continue.

页面会破坏用户体验.如何删除此屏幕?

提前致谢.

注意:如果FB应用程序安装在设备中,我们将不会看到此问题.仅当FB应用程序在设备中不可用时才会引发此问题.

解决方法

我正在使用最新的Facebook SDK 3.6我相信并且已经在HTC One& amp; Galaxy s3 mini.此页面在任何时候都不会显示给我.我在这里遵循API指南……

https://developers.facebook.com/docs/facebook-login

这是代码…也许这可能会有所帮助.

  1. public class LoginHandlerFrag extends Fragment {
  2.  
  3. private UiLifecycleHelper uiHelper;
  4. private static final String TAG = "HomeFragment";
  5. // private ProfilePictureView profilePictureView;
  6.  
  7. private Session.StatusCallback callback = new Session.StatusCallback() {
  8. @Override
  9. public void call(Session session,SessionState state,Exception exception) {
  10. onSessionStateChange(session,state,exception);
  11. }
  12. };
  13.  
  14. @Override
  15. public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
  16. View view = inflater.inflate(R.layout.fragment_login,container,false);
  17.  
  18. LoginButton authButton = (LoginButton) view
  19. .findViewById(R.id.authButton);
  20.  
  21. authButton.setReadPermissions(Arrays.asList("email","user_location","user_birthday","user_likes","user_photos"));
  22. authButton.setFragment(this);
  23.  
  24. Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
  25.  
  26. return view;
  27. }
  28.  
  29. private void makeMeRequest(final Session session) {
  30. // Make an API call to get user data and define a
  31. // new callback to handle the response.
  32. Request request = Request.newMeRequest(session,new Request.GraphUserCallback() {
  33. @Override
  34. public void onCompleted(GraphUser user,Response response) {
  35.  
  36. // If the response is successful
  37. if (session == Session.getActiveSession()) {
  38. if (user != null) {
  39. // profilePictureView.setProfileId(user.getId());
  40. }
  41. }
  42. if (response.getError() != null) {
  43. // Handle errors,will do so later.
  44. }
  45. }
  46. });
  47. request.executeAsync();
  48. }
  49.  
  50. @Override
  51. public void onCreate(Bundle savedInstanceState) {
  52. super.onCreate(savedInstanceState);
  53. uiHelper = new UiLifecycleHelper(getActivity(),callback);
  54. uiHelper.onCreate(savedInstanceState);
  55. }
  56.  
  57. private void onSessionStateChange(Session session,Exception exception) {
  58. session = Session.getActiveSession();
  59. SharedPreferences storedPrefs = PreferenceManager
  60. .getDefaultSharedPreferences(getActivity().getApplicationContext());
  61. SharedPreferences.Editor editor = storedPrefs.edit();
  62. editor.putBoolean("userLoggedTracker",true);
  63. editor.commit();
  64.  
  65. if (state.isOpened()) {
  66. Log.i(TAG,"Logged in...");
  67. makeMeRequest(session);
  68. editor.putBoolean("userLoggedTracker",false);
  69. editor.commit();
  70. getView().setVisibility(View.GONE);
  71.  
  72. } else if (state.isClosed()) {
  73. Log.i(TAG,"Logged out...");
  74. editor.putBoolean("userLoggedTracker",true);
  75. editor.commit();
  76. getView().setVisibility(View.VISIBLE);
  77. }
  78. }
  79.  
  80. @Override
  81. public void onResume() {
  82. super.onResume();
  83.  
  84. Session session = Session.getActiveSession();
  85. if (session != null && (session.isOpened() || session.isClosed())) {
  86. onSessionStateChange(session,session.getState(),null);
  87. }
  88. uiHelper.onResume();
  89. }
  90.  
  91. @Override
  92. public void onActivityResult(int requestCode,int resultCode,Intent data) {
  93. super.onActivityResult(requestCode,resultCode,data);
  94. uiHelper.onActivityResult(requestCode,data);
  95. }
  96.  
  97. @Override
  98. public void onPause() {
  99. super.onPause();
  100. uiHelper.onPause();
  101. }
  102.  
  103. @Override
  104. public void onDestroy() {
  105. super.onDestroy();
  106. uiHelper.onDestroy();
  107. }
  108.  
  109. @Override
  110. public void onSaveInstanceState(Bundle outState) {
  111. super.onSaveInstanceState(outState);
  112. uiHelper.onSaveInstanceState(outState);
  113. }
  114. }

猜你在找的Android相关文章