引言:
有Landi,Newland,银联等智能pos机开发,本文档以MagCard为例,其他相关操作调用类似,本文档仅供学习

详情:
Landi相关文档和newland相关文档,都以MagCard为例

流程:

Landi pos机MagCard调用流程:
1:导入landi提供的eptapilibrary.jar包

compile files('src/main/jniLibs/armeabi/eptapilibrary.jar')

2:初始化MagCardReader,通过调用getInstance方法

MagCardReader.getInstance().searchCard(listener);

3:在activity中使用范例

 MagCardReader.OnSearchListener listener = new MagCardReader.OnSearchListener() {@Overridepublic void onCrash() {}@Overridepublic void onFail(int code) {String errorMessage = getErrorDescription(code);showErrorMessage("ERROR ["+errorMessage+"]");}@Overridepublic void onCardStriped(boolean[] hasTrack, String[] track) {StringBuilder infoBuilder = new StringBuilder();for(int i=0; i<3; i++) {infoBuilder.append("TRACK ");infoBuilder.append(i+1);infoBuilder.append(" - exist ? ");infoBuilder.append(hasTrack[i]);if(hasTrack[i]) {infoBuilder.append(" [");infoBuilder.append(track[i]);infoBuilder.append("]");}infoBuilder.append("\n");}infoBuilder.append("\n\n");infoBuilder.deleteCharAt(infoBuilder.length()-1);displayMagCardInfo(infoBuilder.toString());}@Overridepublic boolean checkValid(int[] trackStates, String[] track) {if(trackStates[1] != TRACK_STATE_NULL && trackStates[1]  != TRACK_STATE_OK) {return false;}if(track[1].length() < 21 || track[1].length() > 37) {return false;}if(track[1].indexOf('=') < 12) {return false;}if(trackStates[1] == TRACK_STATE_NULL && trackStates[2] == TRACK_STATE_NULL) {return false;}return true;};public String getErrorDescription(int code) {switch(code) {case ERROR_NODATA:return "no data";case ERROR_NEEDSTART:return "need restart search";//This error never happenedcase ERROR_INVALID:return "has invalid track";//}return "unknown error - "+code;}};public void searchCard() {try {MagCardReader.getInstance().searchCard(listener);} catch (RequestException e) {e.printStackTrace();}}

Newland POS机MagCard调用流程:
1:导入厂商提供的sdkserviceapi.jar包

2:manifest.xml配置service

 <service android:name=".service.MyService"><intent-filter><action android:name="com.zacloud.device_service" /></intent-filter></service>

3:理解设备接口服务IDeviceService,这是接口具体信息,只是看看而已

public interface IDeviceService extends IInterface {IBinder getBeeper() throws RemoteException;IBinder getLed() throws RemoteException;IBinder getSerialPort() throws RemoteException;IBinder getScanner(int var1) throws RemoteException;IBinder getMagCardReader() throws RemoteException;IBinder getInsertCardReader() throws RemoteException;IBinder getRFCardReader() throws RemoteException;IBinder getPinpad(int var1) throws RemoteException;IBinder getPrinter() throws RemoteException;IBinder getPBOC() throws RemoteException;IBinder getDeviceInfo() throws RemoteException;public abstract static class Stub extends Binder implements IDeviceService {private static final String DESCRIPTOR = "com.zacloud.deviceservice.aidl.IDeviceService";static final int TRANSACTION_getBeeper = 1;static final int TRANSACTION_getLed = 2;static final int TRANSACTION_getSerialPort = 3;static final int TRANSACTION_getScanner = 4;static final int TRANSACTION_getMagCardReader = 5;static final int TRANSACTION_getInsertCardReader = 6;static final int TRANSACTION_getRFCardReader = 7;static final int TRANSACTION_getPinpad = 8;static final int TRANSACTION_getPrinter = 9;static final int TRANSACTION_getPBOC = 10;static final int TRANSACTION_getDeviceInfo = 11;public Stub() {this.attachInterface(this, "com.zacloud.deviceservice.aidl.IDeviceService");}public static IDeviceService asInterface(IBinder obj) {if (obj == null) {return null;} else {IInterface iin = obj.queryLocalInterface("com.zacloud.deviceservice.aidl.IDeviceService");return (IDeviceService)(iin != null && iin instanceof IDeviceService ? (IDeviceService)iin : new IDeviceService.Stub.Proxy(obj));}}public IBinder asBinder() {return this;}public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {IBinder _result;IBinder _result;int _arg0;switch(code) {case 1:data.enforceInterface("com.zacloud.deviceservice.aidl.IDeviceService");_result = this.getBeeper();reply.writeNoException();reply.writeStrongBinder(_result);return true;case 2:data.enforceInterface("com.zacloud.deviceservice.aidl.IDeviceService");_result = this.getLed();reply.writeNoException();reply.writeStrongBinder(_result);return true;case 3:data.enforceInterface("com.zacloud.deviceservice.aidl.IDeviceService");_result = this.getSerialPort();reply.writeNoException();reply.writeStrongBinder(_result);return true;case 4:data.enforceInterface("com.zacloud.deviceservice.aidl.IDeviceService");_arg0 = data.readInt();_result = this.getScanner(_arg0);reply.writeNoException();reply.writeStrongBinder(_result);return true;case 5:data.enforceInterface("com.zacloud.deviceservice.aidl.IDeviceService");_result = this.getMagCardReader();reply.writeNoException();reply.writeStrongBinder(_result);return true;case 6:data.enforceInterface("com.zacloud.deviceservice.aidl.IDeviceService");_result = this.getInsertCardReader();reply.writeNoException();reply.writeStrongBinder(_result);return true;case 7:data.enforceInterface("com.zacloud.deviceservice.aidl.IDeviceService");_result = this.getRFCardReader();reply.writeNoException();reply.writeStrongBinder(_result);return true;case 8:data.enforceInterface("com.zacloud.deviceservice.aidl.IDeviceService");_arg0 = data.readInt();_result = this.getPinpad(_arg0);reply.writeNoException();reply.writeStrongBinder(_result);return true;case 9:data.enforceInterface("com.zacloud.deviceservice.aidl.IDeviceService");_result = this.getPrinter();reply.writeNoException();reply.writeStrongBinder(_result);return true;case 10:data.enforceInterface("com.zacloud.deviceservice.aidl.IDeviceService");_result = this.getPBOC();reply.writeNoException();reply.writeStrongBinder(_result);return true;case 11:data.enforceInterface("com.zacloud.deviceservice.aidl.IDeviceService");_result = this.getDeviceInfo();reply.writeNoException();reply.writeStrongBinder(_result);return true;case 1598968902:reply.writeString("com.zacloud.deviceservice.aidl.IDeviceService");return true;default:return super.onTransact(code, data, reply, flags);}}private static class Proxy implements IDeviceService {private IBinder mRemote;Proxy(IBinder remote) {this.mRemote = remote;}public IBinder asBinder() {return this.mRemote;}public String getInterfaceDescriptor() {return "com.zacloud.deviceservice.aidl.IDeviceService";}public IBinder getBeeper() throws RemoteException {Parcel _data = Parcel.obtain();Parcel _reply = Parcel.obtain();IBinder _result;try {_data.writeInterfaceToken("com.zacloud.deviceservice.aidl.IDeviceService");this.mRemote.transact(1, _data, _reply, 0);_reply.readException();_result = _reply.readStrongBinder();} finally {_reply.recycle();_data.recycle();}return _result;}public IBinder getLed() throws RemoteException {Parcel _data = Parcel.obtain();Parcel _reply = Parcel.obtain();IBinder _result;try {_data.writeInterfaceToken("com.zacloud.deviceservice.aidl.IDeviceService");this.mRemote.transact(2, _data, _reply, 0);_reply.readException();_result = _reply.readStrongBinder();} finally {_reply.recycle();_data.recycle();}return _result;}public IBinder getSerialPort() throws RemoteException {Parcel _data = Parcel.obtain();Parcel _reply = Parcel.obtain();IBinder _result;try {_data.writeInterfaceToken("com.zacloud.deviceservice.aidl.IDeviceService");this.mRemote.transact(3, _data, _reply, 0);_reply.readException();_result = _reply.readStrongBinder();} finally {_reply.recycle();_data.recycle();}return _result;}public IBinder getScanner(int cameraId) throws RemoteException {Parcel _data = Parcel.obtain();Parcel _reply = Parcel.obtain();IBinder _result;try {_data.writeInterfaceToken("com.zacloud.deviceservice.aidl.IDeviceService");_data.writeInt(cameraId);this.mRemote.transact(4, _data, _reply, 0);_reply.readException();_result = _reply.readStrongBinder();} finally {_reply.recycle();_data.recycle();}return _result;}public IBinder getMagCardReader() throws RemoteException {Parcel _data = Parcel.obtain();Parcel _reply = Parcel.obtain();IBinder _result;try {_data.writeInterfaceToken("com.zacloud.deviceservice.aidl.IDeviceService");this.mRemote.transact(5, _data, _reply, 0);_reply.readException();_result = _reply.readStrongBinder();} finally {_reply.recycle();_data.recycle();}return _result;}public IBinder getInsertCardReader() throws RemoteException {Parcel _data = Parcel.obtain();Parcel _reply = Parcel.obtain();IBinder _result;try {_data.writeInterfaceToken("com.zacloud.deviceservice.aidl.IDeviceService");this.mRemote.transact(6, _data, _reply, 0);_reply.readException();_result = _reply.readStrongBinder();} finally {_reply.recycle();_data.recycle();}return _result;}public IBinder getRFCardReader() throws RemoteException {Parcel _data = Parcel.obtain();Parcel _reply = Parcel.obtain();IBinder _result;try {_data.writeInterfaceToken("com.zacloud.deviceservice.aidl.IDeviceService");this.mRemote.transact(7, _data, _reply, 0);_reply.readException();_result = _reply.readStrongBinder();} finally {_reply.recycle();_data.recycle();}return _result;}public IBinder getPinpad(int kapId) throws RemoteException {Parcel _data = Parcel.obtain();Parcel _reply = Parcel.obtain();IBinder _result;try {_data.writeInterfaceToken("com.zacloud.deviceservice.aidl.IDeviceService");_data.writeInt(kapId);this.mRemote.transact(8, _data, _reply, 0);_reply.readException();_result = _reply.readStrongBinder();} finally {_reply.recycle();_data.recycle();}return _result;}public IBinder getPrinter() throws RemoteException {Parcel _data = Parcel.obtain();Parcel _reply = Parcel.obtain();IBinder _result;try {_data.writeInterfaceToken("com.zacloud.deviceservice.aidl.IDeviceService");this.mRemote.transact(9, _data, _reply, 0);_reply.readException();_result = _reply.readStrongBinder();} finally {_reply.recycle();_data.recycle();}return _result;}public IBinder getPBOC() throws RemoteException {Parcel _data = Parcel.obtain();Parcel _reply = Parcel.obtain();IBinder _result;try {_data.writeInterfaceToken("com.zacloud.deviceservice.aidl.IDeviceService");this.mRemote.transact(10, _data, _reply, 0);_reply.readException();_result = _reply.readStrongBinder();} finally {_reply.recycle();_data.recycle();}return _result;}public IBinder getDeviceInfo() throws RemoteException {Parcel _data = Parcel.obtain();Parcel _reply = Parcel.obtain();IBinder _result;try {_data.writeInterfaceToken("com.zacloud.deviceservice.aidl.IDeviceService");this.mRemote.transact(11, _data, _reply, 0);_reply.readException();_result = _reply.readStrongBinder();} finally {_reply.recycle();_data.recycle();}return _result;}}}
}

4:在MyService中绑定和解绑IDeviceService

 private  static IDeviceService deviceService;private ServiceConnection serviceConnection = new ServiceConnection() {@Overridepublic void onServiceDisconnected(ComponentName name) {deviceService = null;}@Overridepublic void onServiceConnected(ComponentName name, IBinder service) {deviceService = IDeviceService.Stub.asInterface(service);}};public void connectDevice(Context paramContext)throws Exception {if (deviceService == null) {Intent intent = new Intent();intent.setPackage("com.zacloud.deviceservice");intent.setAction("com.zacloud.device_service");bindService(intent, serviceConnection, BIND_AUTO_CREATE);} else {}}private void  disconnectDevice() {if (deviceService != null) {try {unbindService(serviceConnection);} catch (Exception e) {e.printStackTrace();} finally {deviceService = null;}} else {}}public static IDeviceService getDeviceService() {return deviceService;}public void onCreate() {super.onCreate();try {connectDevice(this);} catch (Exception e) {e.printStackTrace();}}public void onDestroy() {super.onDestroy();disconnectDevice();}public IBinder onBind(Intent intent) {return null;}public boolean onUnbind(Intent paramIntent) {disconnectDevice();return false;}

5:在MainActivity onCreate()启动MyService

 startService(new Intent(this, MyService.class));

6:在需求activity中初始化IMagCardReader

IMagCardReader magCardReader =IMagCardReader.Stub.asInterface(MyService.getDeviceService().getMagCardReader());

7:调用searchCard()方法,实现MagCardListener

new Thread(new Runnable() {@Overridepublic void run() {try {magCardReader.searchCard(60, new MagCardListener.Stub() {@Overridepublic void onTimeout() throws RemoteException {}@Overridepublic void onSuccess(final Bundle bundle) throws RemoteException {Log.i("magic", "卡号:" + bundle.getString("PAN"));Log.i("magic", "TRACK1:" + bundle.getString("TRACK1"));Log.i("magic", "TRACK2:" + bundle.getString("TRACK2"));Log.i("magic", "TRACK3:" + bundle.getString("TRACK3"));Log.i("magic", "SERVICE_CODE:" + bundle.getString("SERVICE_CODE"));Log.i("magic", "EXPIRED_DATE:" + bundle.getString("EXPIRED_DATE"));runOnUiThread(new Runnable() {@Overridepublic void run() {pan = bundle.get("PAN").toString();if (pan != null) {numEt.setText(pan);}}});}@Overridepublic void onError(int errorCode) throws RemoteException {switch (errorCode) {case 90:Log.i("magic", "刷卡失败");break;case 99:Log.i("magic", "设备服务异常");break;case 100:Log.i("magic", "请求异常");break;default:Log.i("magic", "请求异常");break;}}});} catch (Exception e) {Log.i("magic", "磁条卡寻卡异常");}}}).start();

本文仅供参考,谢谢

Android POS开发相关推荐

  1. Android多媒体开发

    Android多媒体开发系列文章 Android多媒体开发:录音机 Android多媒体开发:照相机 TextureView+MediaPlayer实现在线短视频播放 Android多媒体开发:第三方 ...

  2. Android NFC开发详细总结

    Android NFC开发详细总结 Near Field Communication (NFC) 为一短距离无线通信技术,通常有效通讯距离为4厘米以内.NFC工作频率为13.65 兆赫兹,通信速率为1 ...

  3. Android 后台开发

    Android 开发后台 再在servlet包下面创建LoginDateServlet 服务 package com.hxb.servlet;import java.io.IOException; i ...

  4. Android NFC开发概述

    NFC手机相比普通手机来说,有以下3个附加功能:  1.可以当成POS机来用,也就是"读取"模式   2.可以当成一张卡来刷,也就是NFC技术最核心的移动支付功能  3.可以像蓝牙 ...

  5. Android商城开发----点击加入购物车,购物车商品的增删减

    Android商城开发----点击加入购物车,购物车商品的增删减 上一章节:[分类页面]点击左侧类别,实现右侧对应类别商品的展示 本文是在上一章节基础上开发的,点击[分类]页面商品的加入购物车按钮,实 ...

  6. libgdx教程_使用libgdx进行Android游戏开发–一天中的原型,第1a部分

    libgdx教程 在本文中,我将绕开游戏引擎和组件的构建模块,并演示如何使用libgdx库快速制作游戏原型. 您将学到什么: 创建一个非常简单的2D Shooter Platformer游戏. 完整的 ...

  7. libgdx开发指南_使用libgdx进行Android游戏开发–一天中的原型,第1a部分

    libgdx开发指南 在本文中,我将绕开游戏引擎和组件的构建模块,并演示如何使用libgdx库快速制作游戏原型. 您将学到什么: 创建一个非常简单的2D Shooter Platformer游戏. 完 ...

  8. Android游戏开发十日通(7)- 开发一个双人游戏

    提要 游戏需要分享才能获得快乐,想想你以前玩过的那些游戏,那些会是真正地存在你婶婶的脑海里?是独自一人躲在被窝里酣战PSP,还是和哥们在网吧一起开黑?是一个人单刷迅龙三连,还是和朋友联机怒刷黄黑龙? ...

  9. Android WiFi开发教程(三)——WiFi热点数据传输

    在上一篇文章中介绍了WiFi的搜索和连接,如果你还没阅读过,建议先阅读上一篇Android WiFi开发教程(二)--WiFi的搜索和连接.本篇接着简单介绍手机上如何通过WiFi热点进行数据传输. 跟 ...

  10. android ble 设备扫描程序,Android应用开发Android 7.0 BLE scan 问题:程序无错但扫描不到BLE设备...

    本文将带你了解Android应用开发Android 7.0  BLE scan 问题:程序无错但扫描不到BLE设备,希望本文对大家学Android有所帮助. < 最近在做毕设,需要几周内从头学起 ...

最新文章

  1. 获取SQLServer数据库中所有表
  2. Visual Studio提示Bonjour backend初始化失败
  3. 解决chrome浏览器us-yahoo.com搜索劫持
  4. 半透明AlphaBlend
  5. 按关键字截取linux日志,linux awk截取数据,如何根据第二部分数据的关键字‘aaaaa’获取整串数据...
  6. angular中如何定义全局变量_angularjs 设置全局变量的方法
  7. ANSYS——相同模型不同创建方式的同载荷同约束下的比较
  8. linux c select函数使用求解释
  9. 虚拟机非正常关闭 无法打开
  10. C++中的位域(bit-filed):一种节省空间的成员
  11. 计算机电缆头子怎么做,电缆头制作怎么算量怎么套定额
  12. Linux学习总结(75)—— Linux history 命令实用技巧
  13. Linux里的/dev/null和21和基本符号
  14. MyEclipse 7.0 + PHPEclipse下调试环境搭建(xDebug)
  15. realtek高清晰音频管理器怎么关闭的方法
  16. Mac谷歌浏览器chromedriver驱动安装教程,实现浏览器自动化
  17. 计算机博弈 期望搜索算法算法 期望极大极小算法
  18. Foxmail设置方法
  19. 遗传算法求一元函数的最大值(python)
  20. OpenOCD failed tor read memory at $addr 错误

热门文章

  1. 【毕业设计】深度学习 YOLO 实现车牌识别算法
  2. 小程序“头脑王者” 因违规被微信下架整改 小程序不可逾越的红线
  3. java mysql 分页_mysql分页查询总结
  4. 关于如何取消萤石云视频加密
  5. python类库包括_python类库大全
  6. 小程序tabBar无效
  7. ILSVRC2012(ImageNet2012)数据集的下载及ILSVRC2012_img_val数据集的分类
  8. UltraEdit 26 总是偶尔提示运行的是试用模式
  9. Win10 远程桌面登陆闪退问题处理
  10. 全国行政区划数据 - JSON