【发布时间】:2014-07-09 10:58:08
【问题描述】:
我已经问过这个问题here,但它被标记为重复 - 但是我没有发现 cmets 中提到的任何有用的解决方案。 在这里,我再次询问更多细节......
我正在 HCE 上做一个示例应用 (PoC),并根据 Android 用户指南使用 HostApduService。我创建了两个应用程序
1) ReaderApp - 充当读卡器
2) HCEApp - 模拟卡片
在 HCEApp 中,我创建了一个扩展 HostApduService 的类 'MyService'
public class MyService extends HostApduService {
private int messageCounter;
private final String TAG = "MyService";
Intent mIntent;
@Override
public void onCreate() {
super.onCreate();
Log.i(TAG, "onCreate");
mIntent = new Intent(this, MyActivity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(mIntent);
}
/**
* returned bytes will be sent as response. This method runs in Main thread
* so return ASAP.
*/
@Override
public byte[] processCommandApdu(byte[] apdu, Bundle extras) {
if (selectAidApdu(apdu)) {
Log.i(TAG, "Application selected");
return getWelcomeMessage();
} else {
Log.i(TAG, "Received: " + new String(apdu));
return getNextMessage();
}
}
private byte[] getWelcomeMessage() {
return "Hello Desktop!".getBytes();
}
private byte[] getNextMessage() {
return ("Message from android: " + messageCounter++).getBytes();
}
private boolean selectAidApdu(byte[] apdu) {
if (apdu != null) {
for (byte b : apdu) {
System.out.printf("0x%02X", b);
}
}
return apdu.length >= 2 && apdu[0] == (byte) 0
&& apdu[1] == (byte) 0xa4;
}
@Override
public void onDeactivated(int reason) {
Log.i(TAG, "Deactivated: " + reason);
}
@Override
public boolean onUnbind(Intent intent) {
return super.onUnbind(intent);
}
}
正如您在 onCreate() 中看到的,我正在启动 MyActivity 提供用户输入一些信息,需要将其发送回 MyService。
我认为我不能使用绑定,因为 'onBind()' 在 HostApduService 中被声明为 final,如下所示
@Override
public final IBinder onBind(Intent intent) {
return mMessenger.getBinder();
}
如果我理解正确,请告诉我。感谢任何帮助。
谢谢
iuq
【问题讨论】:
-
我添加了指向 HostApduService 的链接。你能解释一下(链接到)什么是 PoC、pos 和 HCE?
-
@k3b 我添加了指向 HCE 的链接,并将 PoC 替换为示例应用程序,并将 POS 替换为读卡器。希望在上下文中更容易理解!
-
那么...您的问题是什么?你可以使用
onBind,即使它被声明为final。 -
@Manu 感谢您的回复。您能否发布一个示例/示例?我的目标是通过“MyService”启动的“MyActivity”与“MyService”进行通信。
标签: android android-activity android-service