Android指纹识别API讲解,一种更快更好的用户体验(1)

这是一个非常简易的指纹认证界面,相信没什么需要解释的地方。界面大致样式如下图所示。

注意,通常为了让用户清楚的知道现在需要进行指纹认证,Google 官方建议最好使用一个通用的指纹图标,而不应该由各 APP 制作自己的指纹图标。为此,Google 也特意提供了一套指纹认证的组图,可以 点击这里 查看和下载。

接着我们创建一个 FingerprintDialogFragment 类,并让它继承自 DialogFragment,用于作为提示用户进行指纹认证的对话框,代码如下所示:

@TargetApi(23)
public class FingerprintDialogFragment extends DialogFragment {

private FingerprintManager fingerprintManager;

private CancellationSignal mCancellationSignal;

private Cipher mCipher;

private LoginActivity mActivity;

private TextView errorMsg;

/**

  • 标识是否是用户主动取消的认证。
    */
    private boolean isSelfCancelled;

public void setCipher(Cipher cipher) {
mCipher = cipher;
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
mActivity = (LoginActivity) getActivity();
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
fingerprintManager = getContext().getSystemService(FingerprintManager.class);
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Material_Light_Dialog);
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fingerprint_dialog, container, false);
errorMsg = v.findViewById(R.id.error_msg);
TextView cancel = v.findViewById(R.id.cancel);
cancel.setOnClickListener(new View.OnClickListener() {<

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值