我已經提出過這個問題here但它被標記爲重複 - 但是我沒有找到任何解決方法有助於在評論中提到。 在這裏,我有更多的細節再次問...如何與活動中的HostApduService進行通信
我上HCE做一個示例應用程序(POC),並使用HostApduService按照Android的用戶指南。我已經創建了兩個應用
1)ReaderApp - 充當讀卡器 2)HCEApp - 模擬一個卡
在HCEApp,我已經創建了一個類 '爲MyService' 延伸HostApduService
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爲用戶提供了一些信息並需要發送回MyServic e。
我想我不能用綁定爲「onBind()」聲明最後在HostApduService如下
@Override
public final IBinder onBind(Intent intent) {
return mMessenger.getBinder();
}
請讓我知道如果我正確understading它。感謝任何幫助。
感謝
iuq
我已經添加了一個鏈接到HostApduService。你能解釋一下(鏈接到)什麼PoC,pos和HCE是什麼? – k3b
@ k3b我已添加鏈接到HCE,並用示例應用和POS讀卡器替換了PoC。希望在上下文中更容易理解! – iuq
那麼......你的問題是什麼?即使它被聲明爲final,你也可以使用'onBind'。 – Manu