2016-08-29 9 views
2

(Android 6.0以降では)ネイティブAndroid Fingerprint APIを使用してユーザーを認証するアプリケーションを作成しています。あるシナリオでAndroidの指紋api - SCREEN_ONインテントの後にFingerprintManager.AuthenticationCallbackが呼び出されない

- デバイスは、GCMの通知を受信し、画面がオフの場合は電話がロックされていない - アプリは次のフラグとactivityを起動して、デバイスを「ウェイク」:

WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED 

アプリケーションは、ユーザに指で認証するように尋ねるダイアログを表示します。この場合、 - (FingerprintManager.AuthenticationCallbackから - )は、コールバック関数が

と呼ばれていない、ここのコードです:

fingerprintManager.authenticate(null, cancellationSignal, 0, new FingerprintManager.AuthenticationCallback() { 
      @Override 
      public void onAuthenticationError(int errorCode, CharSequence errString) { 
       super.onAuthenticationError(errorCode, errString); 
       logger.info("Authentication error " + errorCode + " " + errString); 
       ... 
      } 

      @Override 
      public void onAuthenticationHelp(int helpCode, CharSequence helpString) { 
       super.onAuthenticationHelp(helpCode, helpString); 
       logger.info("Authentication help message thrown " + helpCode + " " + helpString); 
       ... 
      } 

      @Override 
      public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) { 
       super.onAuthenticationSucceeded(result); 
       logger.info("Authentication succeeded"); 
       ... 
      } 

      /* 
      * Called when authentication failed but the user can try again 
      * When called four times - on the next fail onAuthenticationError(FINGERPRINT_ERROR_LOCKOUT) 
      * will be called 
      */ 
      @Override 
      public void onAuthenticationFailed() { 
       super.onAuthenticationFailed(); 
       logger.info("Authentication failed"); 
       ... 
      } 
     }, null); 

画面が上にあるときに、同じコードが実行されると、それはオフだとき、それはオフだが、ときにオンアクティビティによって - コールバックは呼び出されません。

アイデア? ありがとうございます!

答えて

2

私は同じ問題を気づいたとadb logcatに、私は次の行を見てきました:

W/FingerprintManagerを:認証はすでに

をキャンセルし、私はソースの中に深さで検索しました私はFingerprintManagerに次の関数を見つけたし、コードは:

if (cancel != null) { 
    if (cancel.isCanceled()) { 
     Log.w(TAG, "authentication already canceled"); 
     return; 
    } else { 
     cancel.setOnCancelListener(new OnAuthenticationCancelListener(crypto)); 
    } 
} 

これは、意味あなたは012を入力していること既にと機能しています。cancellationSignalと機能がです。

if(cancellationSignal.isCanceled()){ 
    cancellationSignal = new CancellationSignal(); 
} 

あなたは常に非キャンセルcancellationSignalとあなたのフローが正しいだろう渡しますこの方法:ちょうどあなたのauthenticate()前に次のを追加します。

関連する問題