同じアプリケーションを開発するために、ライブラリ SEEK-For-Android を使用しています。
https://code.google.com/p/seek-for-android/wiki/UsingSmartCardAPIからテスト アプリ HelloSmartCard を実行しようとすると、「接続が拒否されました !!!」というエラーが発生しました。
私はSamsung S IIIと次のコードを使用しています:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
layout.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
button = new Button(this);
button.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
button.setText("Click Me");
button.setEnabled(false);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
Log.i(LOG_TAG, "Retrieve available readers...");
Reader[] readers = seService.getReaders();
if (readers.length < 1)
return;
byte aid[] = new byte[] {(byte)0xA0, 0x00,0x00,0x00,0x03,0x20,0x10};
SECardIdentifier id = new SECardIdentifier(aid);
Log.i(LOG_TAG, "Create Session from the first reader...");
Session session = readers[0].openSession();
Log.i(LOG_TAG, String.valueOf(session.getReader().getName())+" "+id.getAid().toString());
Log.i(LOG_TAG, "Create logical channel within the session...");
Channel channel = session.openLogicalChannel(aid);
Log.i(LOG_TAG, "Send HelloWorld APDU command");
byte[] respApdu = channel.transmit(new byte[] {
(byte) 0x90, 0x10, 0x00, 0x00, 0x00 });
channel.close();
// Parse response APDU and show text but remove SW1 SW2 first
byte[] helloStr = new byte[respApdu.length - 2];
System.arraycopy(respApdu, 0, helloStr, 0, respApdu.length - 2);
Toast.makeText(MainActivity.this, new String(helloStr), Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e(LOG_TAG, "Error occured:", e);
return;
}
}
});
layout.addView(button);
setContentView(layout);
try {
Log.i(LOG_TAG, "creating SEService object");
seService = new SEService(this, this);
} catch (SecurityException e) {
Log.e(LOG_TAG, "Binding not allowed, uses-permission org.simalliance.openmobileapi.SMARTCARD?");
} catch (Exception e) {
Log.e(LOG_TAG, "Exception: " + e.getMessage());
}
}
@Override
protected void onDestroy() {
if (seService != null && seService.isConnected()) {
seService.shutdown();
}
super.onDestroy();
}
public void serviceConnected(SEService service) {
Log.i(LOG_TAG, "seviceConnected()");
button.setEnabled(true);
}
そしてそれは次の例外を返します:
05-13 11:23:09.979: I/HelloSmartcard(17588): creating SEService object
05-13 11:23:09.984: V/SEService(17588): bindService successful
05-13 11:23:10.054: I/HelloSmartcard(17588): seviceConnected()
05-13 11:23:10.054: V/SEService(17588): Service onServiceConnected
05-13 11:23:11.444: I/HelloSmartcard(17588): Retrieve available readers...
05-13 11:23:11.444: I/HelloSmartcard(17588): Create Session from the first reader...
05-13 11:23:11.444: I/HelloSmartcard(17588): SIM: UICC A0000000032010
05-13 11:23:11.444: I/HelloSmartcard(17588): Create logical channel within the session...
05-13 11:23:11.634: E/HelloSmartcard(17588): Error occured:
05-13 11:23:11.634: E/HelloSmartcard(17588): java.lang.SecurityException: Connection refused !!!
05-13 11:23:11.634: E/HelloSmartcard(17588): at org.simalliance.openmobileapi.SEService.checkForException(SEService.java:553)
05-13 11:23:11.634: E/HelloSmartcard(17588): at org.simalliance.openmobileapi.SEService.openLogicalChannel(SEService.java:365)
05-13 11:23:11.634: E/HelloSmartcard(17588): at org.simalliance.openmobileapi.Session.openLogicalChannel(Session.java:131)
05-13 11:23:11.634: E/HelloSmartcard(17588): at com.example.com.pentegy.nfctest.MainActivity$1.onClick(MainActivity.java:65)
05-13 11:23:11.634: E/HelloSmartcard(17588): at android.view.View.performClick(View.java:4211)
05-13 11:23:11.634: E/HelloSmartcard(17588): at android.view.View$PerformClick.run(View.java:17267)
05-13 11:23:11.634: E/HelloSmartcard(17588): at android.os.Handler.handleCallback(Handler.java:615)
05-13 11:23:11.634: E/HelloSmartcard(17588): at android.os.Handler.dispatchMessage(Handler.java:92)
05-13 11:23:11.634: E/HelloSmartcard(17588): at android.os.Looper.loop(Looper.java:137)
05-13 11:23:11.634: E/HelloSmartcard(17588): at android.app.ActivityThread.main(ActivityThread.java:4898)
05-13 11:23:11.634: E/HelloSmartcard(17588): at java.lang.reflect.Method.invokeNative(Native Method)
05-13 11:23:11.634: E/HelloSmartcard(17588): at java.lang.reflect.Method.invoke(Method.java:511)
05-13 11:23:11.634: E/HelloSmartcard(17588): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
05-13 11:23:11.634: E/HelloSmartcard(17588): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
05-13 11:23:11.634: E/HelloSmartcard(17588): at dalvik.system.NativeStart.main(Native Method)
この問題を解決するのを手伝ってください。