2017-10-06 13 views
0

私は自分のアプリでFirebase phone authを実装しようとしています。 GitHubでfirebase android文書を参照しましたが、SMSでコードを取得できません。Firebase電話認証でコードを受信して​​いません。

なぜ起きているのですか?私はそれを実際のデバイスでテストしています。

また、実際のデバイスにはSIMカードがないため、別のSMSに送信しています。しかし、私はそれが問題ではないと確信しています。そうですか?

これは、事前に

void logIn(){ 

    mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() { 

     @Override 
     public void onVerificationCompleted(PhoneAuthCredential credential) { 
      // This callback will be invoked in two situations: 
      // 1 - Instant verification. In some cases the phone number can be instantly 
      //  verified without needing to send or enter a verification code. 
      // 2 - Auto-retrieval. On some devices Google Play services can automatically 
      //  detect the incoming verification SMS and perform verificaiton without 
      //  user action. 
      Log.d("verification", "onVerificationCompleted:" + credential); 
      // [START_EXCLUDE silent] 
      mVerificationInProgress = false; 
      // [END_EXCLUDE] 

      // [START_EXCLUDE silent] 
      // Update the UI and attempt sign in with the phone credential 
      // [END_EXCLUDE] 
      signInWithPhoneAuthCredential(credential); 
     } 

     @Override 
     public void onVerificationFailed(FirebaseException e) { 
      // This callback is invoked in an invalid request for verification is made, 
      // for instance if the the phone number format is not valid. 
      Log.w("verification", "onVerificationFailed", e); 
      // [START_EXCLUDE silent] 
      mVerificationInProgress = false; 
      // [END_EXCLUDE] 

      if (e instanceof FirebaseAuthInvalidCredentialsException) { 

      } else if (e instanceof FirebaseTooManyRequestsException) { 
       // The SMS quota for the project has been exceeded 
       // [START_EXCLUDE] 
       Snackbar.make(findViewById(android.R.id.content), "Quota exceeded.", 
         Snackbar.LENGTH_SHORT).show(); 
       // [END_EXCLUDE] 
      } 


     } 

     @Override 
     public void onCodeSent(String verificationId, 
           PhoneAuthProvider.ForceResendingToken token) { 
      // The SMS verification code has been sent to the provided phone number, we 
      // now need to ask the user to enter the code and then construct a credential 
      // by combining the code with a verification ID. 
      Log.d("verification", "onCodeSent:" + verificationId); 

      // Save verification ID and resending token so we can use them later 
      mVerificationId = verificationId; 
      mResendToken = token; 


     } 
    }; 

    PhoneAuthProvider.getInstance().verifyPhoneNumber(
      "+79995198722",  // Phone number to verify 
      60,     // Timeout duration 
      TimeUnit.SECONDS, // Unit of timeout 
      this,    // Activity (for callback binding) 
      mCallbacks);  // OnVerificationStateChangedCallbacks 

    mVerificationInProgress = true; 
} 

private void verifyPhoneNumberWithCode(String verificationId, String code) { 
    // [START verify_with_code] 
    PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, code); 
    // [END verify_with_code] 
    signInWithPhoneAuthCredential(credential); 
} 


private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) { 
    mAuth.signInWithCredential(credential) 
      .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
       @Override 
       public void onComplete(@NonNull Task<AuthResult> task) { 
        if (task.isSuccessful()) { 
         // Sign in success, update UI with the signed-in user's information 
         Log.d("signIn", "signInWithCredential:success"); 

         FirebaseUser user = task.getResult().getUser(); 

        } else { 
         // Sign in failed, display a message and update the UI 
         Log.w("signIn", "signInWithCredential:failure", task.getException()); 
         if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) { 

         } 

        } 
       } 
      }); 
} 

おかげで私のコードです!

+1

nice、Frankは編集しましたが、helper .. ingineer .... – Peter

答えて

0

あなたの問題はSHA-1指紋と思われるので、FirebaseコンソールでSHA-1キーを更新する必要があります。

ステップ:

した後、ログイン後、あなたは3点に

  • クリックして、プロジェクトの概要を参照してくださいし、クリックすることができ、プロジェクトの[設定]をクリックします
  • クリックして指を追加

    1. Firebase consoleへ印刷する(下部に)
    2. SHA-1キーを貼り付け、[保存]をクリックします。 SHA-1キーへ

    手順:左パネル

  • からのAndroid Studioで

    1. 選択のGradleあなたのアプリのタスクへ
    2. Go]を選択します - >アンドロイド - > signingReport

    Sha-1キーが表示されます。

    enter image description here

  • 関連する問題