2016-12-18 9 views
0

私のスプラッシュアクティビティのFacebookログインボタンは、次のアクティビティに行くことなくスプラッシュアクティビティを終了しています。 logcatの外観では、onSuccessメソッドは呼び出されていません。とにかくそれを次の活動に進めるには?私が気づいた事のFacebookログインボタン閉じるログインアクティビティ

public class SplashActivity extends Activity { 

    private Intent intent; 
    private Handler mHandler; 
    private Runnable mNextRunnable; 
    private final long SPLASH_TIME = 3000; 
    private VideoView videoHolder; 
    private LoginButton loginButton; 
    private CallbackManager callbackManager; 
    private AccessTokenTracker accessTokenTracker; 
    private ImageView iv; 
    private static final String TAG = SplashActivity.class.getSimpleName(); 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     FacebookSdk.sdkInitialize(getApplicationContext()); 
     setContentView(R.layout.activity_splash); 

//  try { 
//   PackageInfo info = getPackageManager().getPackageInfo(
//     "info.nexrave.nexrave", 
//     PackageManager.GET_SIGNATURES); 
//   for (Signature signature : info.signatures) { 
//    MessageDigest md = MessageDigest.getInstance("SHA"); 
//    md.update(signature.toByteArray()); 
//    Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); 
//   } 
//  } catch (Exception e) { 
// 
//  } 

     Log.d(TAG, "Video about to be called"); 
     //Video settings 
     videoHolder = (VideoView) findViewById(R.id.videoView); 
     Uri video = Uri.parse("android.resource://" + getPackageName() + "/" 
       + R.raw.video_footage); 
     videoHolder.setVideoURI(video); 
     videoHolder.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 
      @Override 
      public void onPrepared(MediaPlayer mp) { 
       mp.setLooping(true); 
      } 
     }); 
     videoHolder.start(); 

     //Facebook settings 
     iv = (ImageView) findViewById(R.id.iv_splash_logo); 
     loginButton = (LoginButton) findViewById(R.id.login_button); 
     // Callback registration 
     callbackManager = CallbackManager.Factory.create(); 
     loginButton.setReadPermissions("public_profile", "email", "user_friends"); 
     Log.d(TAG, "UpdateWithToken Called: registering callback"); 
     loginButton.registerCallback(callbackManager, mCallBack); 
//  AppEventsLogger.activateApp(this); 
     Log.d(TAG, "UpdateWithToken About To Be Called"); 
//  accessTokenTracker = new AccessTokenTracker() { 
//   @Override 
//   protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken newAccessToken) { 
//    updateWithToken(newAccessToken); 
//   } 
//  }; 
     updateWithToken(AccessToken.getCurrentAccessToken()); 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     callbackManager.onActivityResult(requestCode, resultCode, data); 
    } 


    @Override 
    protected void onPause() { 
     super.onPause(); 
     finish(); 
    } 

    private void makeVisible() { 
     iv.setVisibility(View.VISIBLE); 
     iv.bringToFront(); 
     loginButton.setVisibility(View.VISIBLE); 
     loginButton.bringToFront(); 
    } 

    private void updateWithToken(AccessToken currentAccessToken) { 
     Log.d(TAG, "UpdateWithToken Called"); 
     if (currentAccessToken != null) { 
      new Handler().postDelayed(new Runnable() { 

       @Override 
       public void run() { 
        Log.d(TAG, "UpdateWithToken Called: User logged in"); 
        Intent i = new Intent(SplashActivity.this, FeedActivity.class); 
        startActivity(i); 
       } 
      }, SPLASH_TIME); 

     } else { 
      new Handler().postDelayed(new Runnable() { 

       @Override 
       public void run() { 
        Log.d(TAG, "UpdateWithToken Called: Not logged in"); 
        makeVisible(); 
        Log.d(TAG, "UpdateWithToken Called: finished"); 
       } 
      }, SPLASH_TIME); 
     } 
    } 

    private FacebookCallback<LoginResult> mCallBack = new FacebookCallback<LoginResult>() { 
     @Override 
     public void onSuccess(LoginResult loginResult) { 
      // App code 
      Log.d(TAG, "UpdateWithToken Called: Done"); 
      //Placeholder: Need to check firebase to see if already registered 
      intent = new Intent(SplashActivity.this, EnterPhoneNumber.class); 
      startActivity(intent); 
     } 

     @Override 
     public void onCancel() { 
      // App code 
      Log.d(TAG, "UpdateWithToken Called: cancel"); 
     } 

     @Override 
     public void onError(FacebookException exception) { 
      // App code 
      Log.d(TAG, "UpdateWithToken Called: error"); 
     } 
    }; 
} 
+0

logcat出力を提供する...デバッグが難しい場合を除き、 – rafsanahmad007

+0

@ rafsanahmad007 Logcatの出力には、FacebookCallbackのものを除いて、私がそこにあるすべてのログが表示されています – Shane

答えて

0

カップル...

あなたupdateWithTokenであなたのonCreate()で

FacebookSdk.sdkInitialize(getApplicationContext()); 
    callbackManager = CallbackManager.Factory.create(); 
    updateWithToken(AccessToken.getCurrentAccessToken()); 
    accessTokenTracker = new AccessTokenTracker() { 
     @Override 
     protected void onCurrentAccessTokenChanged(AccessToken oldToken, AccessToken newToken) { 
      updateWithToken(newToken); 
     } 
    }; 
    accessTokenTracker.startTracking(); 

    loginButton = (LoginButton) findViewById(R.id.login_button); 
    loginButton.setReadPermissions(Arrays.asList(
      "public_profile", "email", "user_friends")); 
    loginButton.registerCallback(callbackManager, callback); 

Profile profile; 
private ProfileTracker mProfileTracker; 

を宣言()メソッド

private void updateWithToken(AccessToken currentAccessToken) { 

    if (currentAccessToken != null) { 
     //User logged In--do your stuff 
    } else { 
     //user not logged in 
    } 
} 
あなたのコールバックメソッドでも

private FacebookCallback<LoginResult> callback = new FacebookCallback<LoginResult>() { 

    @Override 
    public void onSuccess(LoginResult loginResult) { 
     try { 
      if (Profile.getCurrentProfile() == null) { 
       mProfileTracker = new ProfileTracker() { 
        @Override 
        protected void onCurrentProfileChanged(Profile profile_old, Profile profile_new) { 
         // profile2 is the new profile 
         profile = profile_new; 
         Log.v("facebook - profile", profile_new.getFirstName()); 
         mProfileTracker.stopTracking(); 
        } 
       }; 
       mProfileTracker.startTracking(); 
      } else { 
       profile = Profile.getCurrentProfile(); 
       Log.v("facebook - profile", profile.getFirstName()); 
      } 

      Intent intent = new Intent(getApplicationContext(), EnterPhoneNumber.class); 
      startActivity(intent); 
     } catch (Exception e) { 
      Log.d("ERROR", e.toString()); 
     } 
    } 

    @Override 
    public void onCancel() { 

    } 

    @Override 
    public void onError(FacebookException e) { 
     Log.d("FACEBOOK ERRROR", e.toString()); 
    } 
}; 

またキーハッシュを

がマニフェストにこれを追加開発者のパネルに正しく追加されて確認してください:あなたのレイアウトでも

<activity 
     android:name="com.facebook.FacebookActivity" 
     android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" 
     android:label="@string/app_name" 
     android:theme="@android:style/Theme.Translucent.NoTitleBar" /> 
<meta-data 
     android:name="com.facebook.sdk.ApplicationId" 
     android:value="@string/APP_ID" /> 

を:

<com.facebook.login.widget.LoginButton xmlns:fb="http://schemas.android.com/apk/res-auto" 
       android:id="@+id/login_button" 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:layout_centerHorizontal="true" 
       android:layout_marginBottom="10dp" 
       android:layout_marginLeft="@dimen/activity_left_margin" 
       android:layout_marginRight="@dimen/activity_right_margin" 
       android:background="@drawable/custom_facebook" 
       android:drawableLeft="@drawable/fb" 
       android:drawablePadding="15dp" 
       android:gravity="center" 
       android:padding="10dp" 
       android:singleLine="true" 
       android:text="Login with Facebook" 
       android:textColor="@color/color_white" 
       android:textSize="18sp" 
       android:visibility="visible" /> 
+0

私が追跡を開始しても、accesstokenはまだnullです。 oncallbackメソッドは決して – Shane

+0

と呼ばれることはありません。ハッシュキーが適切に追加され、アンドロイドモニター/ logcatから直接コピーされました。 – Shane

+0

@Shane編集済みの回答を参照してください。それがうまくいかない場合は、アプリをアンインストールしてもう一度やり直してみてください。LoginManagerによって返されたアクセストークンが共有設定 – rafsanahmad007

関連する問題