基于Android NFC传感器读取身份证信息demo
程序员文章站
2022-04-21 11:32:23
摘要:通过导入开发包sdk开发基几Android NFC设备读取身份证信息1. 开发条件: 1)鱼住往来科技的身份验证sdk :下载地址:https://www.yzfuture.cn/views/service/index.html 2)Android Studio3.0以上 3)基于java语言开发,非kotlin语言2.添加包步骤:1)添加以下两个包在Android Studio项目 中相应的依赖文件build.gradle(Module.app)添......
摘要:通过导入开发包sdk开发基几Android NFC设备读取身份证信息
1. 开发条件:
1)鱼住往来科技的身份验证sdk :下载地址:https://www.yzfuture.cn/views/service/index.html
2)Android Studio3.0以上
3)基于java语言开发,非kotlin语言
2.添加包步骤:
1)添加以下两个包
在Android Studio项目 中相应的依赖文件build.gradle(Module.app)添加包的依赖
文件:build.gradle(Module.app):
android {
compileSdkVersion 30
buildToolsVersion "30.0.1"
defaultConfig {
applicationId "com.example.id_test"
minSdkVersion 26
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a','x86', 'x86_64'
}
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath = true
}
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
repositories{
flatDir{
dirs 'libs'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation(name:'yzwlnfcreadcard', ext:'aar')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.3.0'
implementation 'androidx.navigation:navigation-ui:2.3.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
添加好相应的依赖后,gradle一下,就可以引用相应的包了
2)AndroidMainifest.xml 文件添加相应的权限:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.id_test">
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.hardware.camera" />
<uses-permission android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />
</activity>
</application>
</manifest>
注意:其中添加了一种NFC过滤器触发Intent——当NFC感应到过滤器范围中的Card类型时,会触发Intent,并执行一个Activity。
3)app流程
更新中........
本文地址:https://blog.csdn.net/sundy_ywz/article/details/107579249