2013-05-13 114 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卡讀卡器?