指纹的简单使用

class MyCallBack extends FingerprintManager.AuthenticationCallback {
    boolean mSelfCancelled;
    private FingerprintManager fingerPrintManager;
    private CancellationSignal mCancellationSignal;
    TextView prompt;

    Activity mActivity;

    public MyCallBack(FingerprintManager mFingerPrintManager, TextView prompt, Activity mActivity) {
        this.fingerPrintManager = mFingerPrintManager;
        this.prompt = prompt;
        this.mActivity = mActivity;
    }

    public boolean isFingerprintAuthAvailable() {
        return fingerPrintManager.isHardwareDetected()
                && fingerPrintManager.hasEnrolledFingerprints();
    }

    public void startListening(FingerprintManager.CryptoObject cryptoObject) {
        if (!isFingerprintAuthAvailable()) {
            return;
        }
        mCancellationSignal = new CancellationSignal();
        mSelfCancelled = false;
        prompt.setText("");
        fingerPrintManager
                .authenticate(cryptoObject, mCancellationSignal, 0 /* flags */, this, null);
    }

    public void stopListening() {
        if (mCancellationSignal != null) {
            mSelfCancelled = true;
            mCancellationSignal.cancel();
            mCancellationSignal = null;
        }
    }

    @Override
    public void onAuthenticationError(int errorCode, CharSequence errString) {
        super.onAuthenticationError(errorCode, errString);
        LogUtil.d(TAG, "onAuthenticationError");
        prompt.setText("" + errString);
    }

    @Override
    public void onAuthenticationFailed() {
        super.onAuthenticationFailed();
        LogUtil.d(TAG, "onAuthenticationFailed");
        prompt.setText("onAuthenticationFailed");
    }

    @Override
    public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
        super.onAuthenticationSucceeded(result);
        LogUtil.d(TAG, "onAuthenticationSucceeded");
        prompt.setText("");
        if (getActivity() instanceof Login2Activity) {
            ((Login2Activity)getActivity()).goToMain();
        }
        getActivity().finish();
    }

    @Override
    public void onAuthenticationHelp(int helpCode, CharSequence helpString) {
        super.onAuthenticationHelp(helpCode, helpString);
        prompt.setText("" + helpString);
    }
}

调用;

public void onResume() {
    super.onResume();
    if (myCallBack != null) {
        myCallBack.startListening(null);
    }
    ((AnimationDrawable)icon.getDrawable()).start();
}

@Override
public void onPause() {
    super.onPause();
    if (myCallBack != null) {
        myCallBack.stopListening();
    }
    ((AnimationDrawable)icon.getDrawable()).stop();
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值