码迷,mamicode.com
首页 > 移动开发 > 详细

Android HCE开发配置AID响应关系总结

时间:2015-02-28 18:51:19      阅读:416      评论:0      收藏:0      [点我收藏+]

标签:hostapduservice   android   nfc   hce   aid   

开发HCE功能必须使用到HostApduService,在使用HostApduService时需要配置HostApduService的对应AID,同一个手机可能安装多个HCE APP,或者同一个APP包含多个HostApduService,这时候就需要搞清楚配置的AID和对应的HostApduService之间的响应向后问题。

首先介绍一下关于HostApduService的AID配置问题,AID有两种模式:other和payment

第一种

<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:apduServiceBanner="@drawable/icon"
    android:description="@string/servicedesc"
    android:requireDeviceUnlock="false" >
    <!--
          可以通过指定多个aid-filter,来注册多个AID。
          category可以指定为 other 或者 payment。
          requireDeviceUnlock为false的时候,可以在锁屏状态下完成处理,为true的时候,则会要求用户解锁屏幕。
    -->
    <aid-group
        android:category="other"
        android:description="@string/app_name" >
        <aid-filter android:name="@string/AID1" />
    </aid-group>

</host-apdu-service>
第二种

<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:apduServiceBanner="@drawable/alipay"
    android:description="@string/servicedesc"
    android:requireDeviceUnlock="false" >

    <!--
          可以通过指定多个aid-filter,来注册多个AID。
          category可以指定为 other 或者 payment。
          requireDeviceUnlock为false的时候,可以在锁屏状态下完成处理,为true的时候,则会要求用户解锁屏幕
    -->

    <aid-group
        android:category="payment"
        android:description="@string/app_name" >
        <aid-filter android:name="@string/AID2" /> 
    </aid-group>

</host-apdu-service>


下面我们来详细说明一下关于不同模式下的AID响应问题(前提:一个手机,手机上有A、B两个HCE APP,通过读卡器向手机发送APDU选择指令

1、A和B的应用AID设置的都是payment模式,

      只有手机当前选定的默认支付APP会响应,另外一个APP的AID选择指令是不会响应的。

2、A和B的应用AID设置的都是other模式,

      当A和B的AID是相同的时候系统会弹出对话框,列出A和B,让用户选择。

      如果A和B的AID不同,那么两个APP之间没有相互影响。

3、A和B的应用AID设置的分别是payment(A)和other(B)模式,

      如果A和B的AID相同,那么只有A会响应选择指令。

      如果A和B的AID不同,那么两者之间不会相互影响


最后将如何判断当前HCE应用是否是默认支付程序以及如何设置成默认支付程序的方法贡献给大家

	private void checkIsDefaultApp() {
		CardEmulation cardEmulationManager = CardEmulation.getInstance(NfcAdapter.getDefaultAdapter(this));
		ComponentName paymentServiceComponent = new ComponentName(getApplicationContext(), CardMangerService.class.getCanonicalName());
		if (!cardEmulationManager.isDefaultServiceForCategory(paymentServiceComponent, CardEmulation.CATEGORY_PAYMENT)) {
			Intent intent = new Intent(CardEmulation.ACTION_CHANGE_DEFAULT);
			intent.putExtra(CardEmulation.EXTRA_CATEGORY,CardEmulation.CATEGORY_PAYMENT);
			intent.putExtra(CardEmulation.EXTRA_SERVICE_COMPONENT,paymentServiceComponent);
			startActivityForResult(intent, 0);
			L.d("TAG","当前应用不是默认支付,需手动设置");
		} else {
			L.d("TAG","当前应用是系统默认支付程序");
		}
	}




Android HCE开发配置AID响应关系总结

标签:hostapduservice   android   nfc   hce   aid   

原文地址:http://blog.csdn.net/hugege20111029/article/details/43987041

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!