2013-05-13 95 views
1

我正在使用库SEEK-For-Android开发相同的应用程序。寻找机器人。拒绝连接 ! Android

当我尝试运行测试应用程序HelloSmartCard从https://code.google.com/p/seek-for-android/wiki/UsingSmartCardAPI我是采取错误:“连接拒绝!!!”

我使用的是三星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) 

请帮我解决这个问题。

+1

在清单中得到了'<使用权限android:name =“android.permission.INTERNET”/>“? – Bigflow 2013-05-13 08:55:19

+1

对不起。我的应用程序连接到UICC安全元素。所以我不需要互联网连接。 – 2013-05-13 09:01:36

回答

0

我遇到了同样的情况,而在我的情况下seSevice.getReader()抛出异常“连接被拒绝”。也就是说,我连一个读卡器都无法读取。

我看了Google的the following info,希望能帮助解释这种情况。

Samsung did only include the UiccTerminal.java for SIM access and removed the result which is a valid and recommended way to integrate SCAPI into the products.

你能告诉哪个ROM测试正在运行,所以我可以切换到相同的ROM,并获得SIM卡读卡器?