摘要:通过导入开发包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):

PS:android 需要28 的sdk一下:

android {compileSdkVersion 28buildToolsVersion "30.0.1"defaultConfig {applicationId "com.example.id_test"minSdkVersion 26targetSdkVersion 28versionCode 1versionName "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 falseproguardFiles 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-featureandroid:name="android.hardware.nfc"android:required="true" /><applicationandroid: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"><activityandroid: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-dataandroid:name="android.nfc.action.TECH_DISCOVERED"android:resource="@xml/nfc_tech_filter" /></activity></application></manifest>
相应的资源文件:res/xmlnfc_tech_filter.xml——NFC过滤器文件:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"><tech-list><tech>android.nfc.tech.IsoDep</tech><tech>android.nfc.tech.MifareClassic</tech><tech>android.nfc.tech.NfcA</tech></tech-list><tech-list><tech>android.nfc.tech.IsoDep</tech><tech>android.nfc.tech.NfcB</tech><tech>android.nfc.tech.NfcA</tech></tech-list></resources>

注意:其中添加了一种NFC过滤器触发Intent——当NFC感应到过滤器范围中的Card类型时,会触发Intent,并执行一个Activity。

3)app流程

Main.java相应的代码

public class MainActivity extends AppCompatActivity implements ActiveCallBack {private OTGReadCardAPI ReadCardAPI = null;private NfcAdapter nfcAdapter = null;private String mName = null;private String mIDNO = null;private int mSex;private PendingIntent pi = null;private IntentFilter tagDetected = null;private String[][] mTechLists;private NfcAdapter mAdapter = null; // 定义NFC适配器private Intent inintent = null;TextView tv_name, tv_sex, tv_idno;Button bt_act;private boolean bTestServer = false;private boolean bNFC = false;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.act_main);tv_name = findViewById(R.id.name);tv_sex = findViewById(R.id.sex);tv_idno = findViewById(R.id.IDNO);bt_act = findViewById(R.id.bt_action);init();//初始化NFC读卡器//       String m_szAppKey = getSharedPreferences("appConfig",MODE_PRIVATE).getString("AppKey", "");//        ReadCardAPI = new OTGReadCardAPI(getApplicationContext(), this, bNFC);//        bt_act.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {nfcRead(getIntent()); //NFC读信息new MyTask().execute(); //启动线程new Thread(new Runnable() {@Overridepublic void run() {nfcRead(getIntent());}});
//            }
//
//        });PermissionUtil.grantNeedPermission(this); //添加权限}public void nfcRead(Intent intent) {/**5445454225474* NFC读卡过程** */
//        ReadCardAPI = new OTGReadCardAPI(getApplicationContext(), this, false);
//        //配置服务器
//        ArrayList<Serverinfo> twoCardServerlist = new ArrayList<Serverinfo>();
//        twoCardServerlist.add(new Serverinfo("id.yzfuture.cn", 8848));  // TygerZH server测试
//        ReadCardAPI.setServerInfo(twoCardServerlist, null, bTestServer);
//        //读卡
//        nfcAdapter = NfcAdapter.getDefaultAdapter(this);
//        if (nfcAdapter == null) {
//            Toast.makeText(this, "暂不支持NFC功能", Toast.LENGTH_LONG).show();
//            return;
//        }
//        if (nfcAdapter != null && !nfcAdapter.isEnabled()) {
//            Toast.makeText(this, "请在系统设置中先启用NFC功能", Toast.LENGTH_LONG).show();
//            finish();
//            return;
//        }String AppKey = "A2E91A7BF13C75AADB0400B8701FD284"; // 手机号码注册返回的数据AppKeyint code = ReadCardAPI.NfcReadCard(AppKey, null, intent, eCardType.eTwoGeneralCard, "", false);int erro_code = ReadCardAPI.GetErrorCode();if (code == 90) {//解码成功//获取信息mName = ReadCardAPI.GetTwoCardInfo().szTwoIdName;mIDNO = ReadCardAPI.GetTwoCardInfo().szTwoIdNo;mSex = ReadCardAPI.GetTwoCardInfo().nTwoIdSex;tv_name.setText("");tv_sex.setText("");tv_idno.setText("");tv_name.setText(mName);tv_sex.setText(mSex);tv_idno.setText(mIDNO);} else {//解码失败Toast.makeText(this, "解码失败" + code + ":" + erro_code, Toast.LENGTH_LONG).show();}}public void init() {ReadCardAPI = new OTGReadCardAPI(getApplicationContext(), this, bNFC);ArrayList<Serverinfo> twoCardServerlist = new ArrayList<Serverinfo>();twoCardServerlist.add(new Serverinfo("id.yzfuture.cn", 8848));  // TygerZH server测试ReadCardAPI.setServerInfo(twoCardServerlist, null, bTestServer);mAdapter = NfcAdapter.getDefaultAdapter(getApplicationContext());if (mAdapter != null) {init_NFC();} else {if (ReadCardAPI != null) {Toast.makeText(this, "本机不支持NFC功能", Toast.LENGTH_SHORT).show();}}}private void init_NFC() {pi = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);tagDetected = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);//.ACTION_TAG_DISCOVERED);tagDetected.addCategory(Intent.CATEGORY_DEFAULT);mTechLists = new String[][]{new String[]{NfcB.class.getName()}, new String[]{NfcA.class.getName()}};if (mAdapter != null && !mAdapter.isEnabled()) {Toast.makeText(this, "NFC尚未开启", Toast.LENGTH_SHORT).show();}}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.menu_main, menu);return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// Handle action bar item clicks here. The action bar will// automatically handle clicks on the Home/Up button, so long// as you specify a parent activity in AndroidManifest.xml.int id = item.getItemId();//noinspection SimplifiableIfStatementif (id == R.id.action_settings) {return true;}return super.onOptionsItemSelected(item);}@Overridepublic void setUserInfo(String s) {}@Overridepublic void DeviceOpenFailed(boolean b, boolean b1) {}@Overridepublic void readProgress(int nprocess) {Message msg = Message.obtain();msg.what = 0;msg.arg1 = nprocess;
//        mHandler.sendMessageDelayed(msg, 0);Log.e("aa", "  " + nprocess);}@Overridepublic void onPointerCaptureChanged(boolean hasCapture) {}@Overrideprotected void onResume() {super.onResume();if (mAdapter != null) {mAdapter.enableForegroundDispatch(this, pi, new IntentFilter[]{tagDetected}, mTechLists);}}@Overrideprotected void onPause() {super.onPause();if (mAdapter != null) {mAdapter.disableForegroundDispatch(this);}}@Overrideprotected void onDestroy() {
//        mHandler.removeCallbacksAndMessages(null);super.onDestroy();}@Overrideprotected void onNewIntent(Intent intent) {super.onNewIntent(intent);inintent = intent;
//        progressBar.setProgress(0);nfcRead(intent);}
}

更新中........

基于Android NFC传感器读取身份证信息demo相关推荐

  1. android通过USB读取身份证信息

    一.USB的通信流程 搜索设备->建立连接->通信 , 全部代码请 "戳这" 1.搜索设备 /*** 获取目标UsbDevice* @param view*/publi ...

  2. 基于华视身份证读卡器读取身份证信息的Android demo

    项目概述 本Demo需要华视的身份证读卡器,连接Android机器设备,当身份证读卡器读取到身份证信息后,立马展示出身份证信息数据.得到身份证的姓名.照片.出生年月等数据. 项目概述 本Demo需要华 ...

  3. 身份证读取设备开发解决方案:2、Android下通过usb转串口读取身份证信息

    身份证读取设备开发解决方案:2.Android下通过usb转串口读取身份证信息 文章目录 身份证读取设备开发解决方案:2.Android下通过usb转串口读取身份证信息 1. 前言 2. 准备 3. ...

  4. web读取身份证信息(java语言)

    其实实现读取身份证信息,代码其实没有多难,关键需要和硬件的厂商协调好,看他们的硬件是否支持二次开发(一般都支持).如果支持我们需要和他们拿到他们底层的jar包和api(接口文档),要是有demo就更好 ...

  5. 浏览器使用华视电子设备读取身份证信息

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家. 对人工智能感兴趣或者想了解的小伙伴,可以点击跳转到网站一起学习哟. https://www.captainai.ne ...

  6. VUE实现华视身份证阅读器读取身份证信息

    VUE实现华视身份证阅读器读取身份证信息 话不多上直接上代码,写的不怎么规范多多包涵,我是在模态框实现的,在这里就只提供模态框代码. 最后附上华视身份证阅读器安装文件和浏览器插件链接: [https: ...

  7. VUE实现华视身份证阅读器读取身份证信息(本文分两种情况,第一中是点击按钮读取信息,一种是自动读取信息)

    本文是用了vue+element来实现华视身份证读卡器读取身份信息的,当然在开发之前要做好前提准备,就是厂家提供对应设备的api和安装对应的驱动.本文通过两种方法来实现读取信息,第一种是点击按钮读取信 ...

  8. Android拍照扫描识别身份证信息SDK

    Android拍照扫描识别身份证信息SDK 移动互联网是大趋势? 随着智能手机的硬件不断优化,移动互联网及应用大范围普及,互联网+各行各业,跨界.融合.创新,市场瞬息万变,有野心的企业和人.技术都在拼 ...

  9. 用python读取身份证信息的功能分析与实现,兼述python调用dll的方法

    背景 有这样一个需求,要求能自动读取用户的身份证信息.如果是一代身份证,这个功能恐怕只能通过图像识别的办法来解决了.不过现在二代身份证已经很普及.客户要求能读二代身份证就可以了. 现在二代身份证阅读器 ...

最新文章

  1. ArrayList与LinkedList区别
  2. Android动态加载进阶 代理Activity模式
  3. VC++环境添加一般类的方法、使用MFC演示基本C++成员变量和成员函数
  4. 服务器重装之后连接不上及解决措施
  5. MIFARE系列5《存储结构》
  6. c primer plus 第6版 中文版pdf_内功实力再精进 试驾上汽大通V80 PLUS城市版_搜狐汽车...
  7. BZOJ 3093: [Fdu校赛2012] A Famous Game
  8. XP下安装SQL2000企业版
  9. Python案例:破译爬虫项目实践活动日期密码
  10. url 的正则表达式:path-to-regexp
  11. 说话人识别----技术挑战点
  12. scite editor on mac
  13. 【懒懒】我不生产笑话,我只是笑话的搬运工 [问题点数:200分]
  14. 修改putty的缺省值设置
  15. JS 截取视频某一帧图片 实现视频截图
  16. 从零开始制作点餐Android app(一)
  17. Java基础面试题(2022版)
  18. 2xx、200、201、202、203、204、205、206 状态码详解
  19. 解决Python官网打不开
  20. FFmpeg Invalid data found when processing input

热门文章

  1. 12、说说梯度下降法
  2. FlowForge 重要组件及概念
  3. JSP网上二手交易商城
  4. 常见EI会议出版商IOP出版计划供参考
  5. 矩阵分析——LU分解
  6. 2k19徽章修改_您可以修改此会议徽章
  7. 可以有效改进项目管理技能的十个过程
  8. IDEA中的单元测试模块(Junit)不能自动导包
  9. ttttttttttt
  10. 中文期刊模板的页面格式,以《电力系统自动化》为例