指纹识别菜鸟问题!

Water Lee 2018-01-01 10:45:14
公司突然要求开发手机端指纹验证登录功能。在网上查了资料,打算试一下的时候,小鸟囧了。
import android.hardware.fingerprint.FingerprintManager;
报错:The import android.hardware.fingerprint cannot be resolved
一直用C#做winform开发,Android还是菜鸟,求各路大师帮忙!
...全文
424 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Water Lee 2018-01-07
  • 打赏
  • 举报
回复
引用 3 楼 a511341250 的回复:
[quote=引用 2 楼 waterljb 的回复:] 我也查了下,发现我的最高是 android-4.4,应该要 android-6.0以上才有指纹识别,但这个要怎么增加,或是要下载什么文件。我都忘了当时是从哪里下的eclipse了。
建议还是使用android studio吧。 推荐你个网址 http://www.androiddevtools.cn/ 这里有你想要的[/quote] 最终还是决定换 android studio 了,一是没有太多时间去弄清要添加什么文件,二是 as 确实有很多优秀的地方。 感谢帮忙! 不过 已经安装eclipse 生成的apk的手机,再安装 as 生成的apk时,会提示签名不一致,只能把之前的卸载掉才可以,这样会造成原有数据的丢失。我另开一个贴再问了。 同时也感谢回复的各位朋友!
钰娘娘 2018-01-06
  • 打赏
  • 举报
回复
给个小例子: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" android:textSize="18sp" /> <Button android:id="@+id/btn_activity_main_finger" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_below="@+id/textView" android:layout_marginTop="54dp" android:text="指纹识别" android:layout_alignParentLeft="true" /> </LinearLayout> public class FingerActivity extends AppCompatActivity { FingerprintManager manager; KeyguardManager mKeyManager; private final static int REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS = 0; private final static String TAG = "finger_log"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_finger); manager = (FingerprintManager) this.getSystemService(Context.FINGERPRINT_SERVICE); mKeyManager = (KeyguardManager) this.getSystemService(Context.KEYGUARD_SERVICE); Button btn_finger = (Button) findViewById(R.id.btn_activity_main_finger); btn_finger.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isFinger()) { Toast.makeText(FingerActivity.this, "请进行指纹识别", Toast.LENGTH_LONG).show(); Log(TAG, "keyi"); startListening(null); } } }); } public boolean isFinger() { //android studio 上,没有这个会报错 if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(this, "没有指纹识别权限", Toast.LENGTH_SHORT).show(); return false; } Log(TAG, "有指纹权限"); //判断硬件是否支持指纹识别 if (!manager.isHardwareDetected()) { Toast.makeText(this, "没有指纹识别模块", Toast.LENGTH_SHORT).show(); return false; } Log(TAG, "有指纹模块"); //判断 是否开启锁屏密码 if (!mKeyManager.isKeyguardSecure()) { Toast.makeText(this, "没有开启锁屏密码", Toast.LENGTH_SHORT).show(); return false; } Log(TAG, "已开启锁屏密码"); //判断是否有指纹录入 if (!manager.hasEnrolledFingerprints()) { Toast.makeText(this, "没有录入指纹", Toast.LENGTH_SHORT).show(); return false; } Log(TAG, "已录入指纹"); return true; } final android.os.CancellationSignal mCancellationSignal = new android.os.CancellationSignal(); //回调方法 FingerprintManager.AuthenticationCallback mSelfCancelled = new FingerprintManager.AuthenticationCallback() { @Override public void onAuthenticationError(int errorCode, CharSequence errString) { //但多次指纹密码验证错误后,进入此方法;并且,不能短时间内调用指纹验证 Toast.makeText(FingerActivity.this, errString, Toast.LENGTH_SHORT).show(); showAuthenticationScreen(); } @Override public void onAuthenticationHelp(int helpCode, CharSequence helpString) { Toast.makeText(FingerActivity.this, helpString, Toast.LENGTH_SHORT).show(); } @Override public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) { Toast.makeText(FingerActivity.this, "指纹识别成功", Toast.LENGTH_SHORT).show(); } @Override public void onAuthenticationFailed() { Toast.makeText(FingerActivity.this, "指纹识别失败", Toast.LENGTH_SHORT).show(); } }; @RequiresApi(api = Build.VERSION_CODES.M) public void startListening(FingerprintManager.CryptoObject cryptoObject) { //android studio 上,没有这个会报错 if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(this, "没有指纹识别权限", Toast.LENGTH_SHORT).show(); return; } manager.authenticate(cryptoObject, mCancellationSignal, 0, mSelfCancelled, null); } /** * 锁屏密码 */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void showAuthenticationScreen() { Intent intent = mKeyManager.createConfirmDeviceCredentialIntent("finger", "测试指纹识别"); if (intent != null) { startActivityForResult(intent, REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS) { // Challenge completed, proceed with using cipher if (resultCode == RESULT_OK) { Toast.makeText(this, "识别成功", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "识别失败", Toast.LENGTH_SHORT).show(); } } } private void Log(String tag, String msg) { Log.d(tag, msg); } } 权限: <uses-permission android:name="android.permission.USE_FINGERPRINT"></uses-permission> <uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission> 这个可以用的,当然也要有硬件才能用。
Water Lee 2018-01-04
  • 打赏
  • 举报
回复
引用 3 楼 a511341250 的回复:
[quote=引用 2 楼 waterljb 的回复:] 我也查了下,发现我的最高是 android-4.4,应该要 android-6.0以上才有指纹识别,但这个要怎么增加,或是要下载什么文件。我都忘了当时是从哪里下的eclipse了。
建议还是使用android studio吧。 推荐你个网址 http://www.androiddevtools.cn/ 这里有你想要的[/quote] 我才刚刚配置好 eclipse ,而且有一些已有的包都是,现在换开发工具感觉更难。我也在另一台电脑上下了 Android Studio,一早上也没弄好,连启动都没成功。
moonFY 2018-01-04
  • 打赏
  • 举报
回复
AS 安装路径没有中文 就是一直 点next 的怎么会启动不成功?没装SDK ?
ESC尛蜜蜂 2018-01-02
  • 打赏
  • 举报
回复
引用 2 楼 waterljb 的回复:
我也查了下,发现我的最高是 android-4.4,应该要 android-6.0以上才有指纹识别,但这个要怎么增加,或是要下载什么文件。我都忘了当时是从哪里下的eclipse了。
建议还是使用android studio吧。 推荐你个网址 http://www.androiddevtools.cn/ 这里有你想要的
Water Lee 2018-01-02
  • 打赏
  • 举报
回复
我也查了下,发现我的最高是 android-4.4,应该要 android-6.0以上才有指纹识别,但这个要怎么增加,或是要下载什么文件。我都忘了当时是从哪里下的eclipse了。
w22net 2018-01-01
  • 打赏
  • 举报
回复
可能和android的版本有关系吧,不知道你用的啥版本

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧