seek-for-android / pool

Migrated repo from Google Code, contains legacy code and wiki.
159 stars 63 forks source link

Constructor fail #92

Closed mohandasms closed 8 years ago

mohandasms commented 8 years ago

Hi,

The constructor "seService = new SEService(this, this);" being called at onCreate() is returning with log "V/SEService﹕ bindingSuccessful: false". I followed exactly as written in the post. Please advise.

marcobrador commented 8 years ago

Please use the mailing list for this kind of questions (https://groups.google.com/forum/#!forum/seek-for-android). Provider as many details (code snippets, logs, ...) as possible as with this little info it is virtually impossible to help.

Best regards, Marc

mohandasms commented 8 years ago

As requested, please find below code i have implemented

in MainActivity,java i have:

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

    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());
    }
}

public void btnTest_OnClick(View view) { try { Log.i(LOG_TAG, "Retrieve available readers..."); Log.i(LOG_TAG, "seService.isConnected()="+seService.isConnected()); Reader[] readers = seService.getReaders(); if (readers.length < 1) return;

        Log.i(LOG_TAG, "Create Session from the first reader...");
        Session session = readers[0].openSession();

        Log.i(LOG_TAG, "Create logical channel within the session...");
        Channel channel = session.openLogicalChannel(new byte[] {
                (byte)0xD2, (byte)0x76, (byte)0x00, (byte)0x00, (byte)0x28, (byte)0x41,
                (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x89,
                (byte)0x00, (byte)0x00, (byte)0x00 });

        Log.d(LOG_TAG, "Send HelloWorld APDU command");
        byte[] respApdu = channel.transmit(new byte[] { (byte)0xA0, (byte)0xA4, (byte)0x00,
                (byte)0x00, (byte)0x02, (byte)0x3F, (byte)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;
    }
}

And in AndroidManifest.xml i have:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="mohanmorpho.omgandroid" >

<uses-permission android:name="org.simalliance.openmobileapi.SMARTCARD"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <uses-library android:name="org.simalliance.openmobileapi" android:required="true" />
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Now in the log, during install I'm getting: 01-07 22:52:25.570 9883-9883/com.example.mohanmorpho.omgandroid I/HelloSmartcard﹕ creating SEService object 01-07 22:52:25.570 9883-9883/com.example.mohanmorpho.omgandroid V/SEService﹕ bindingSuccessful: false

And upon button click, I'm getting: 01-07 22:52:42.980 9883-9883/com.example.mohanmorpho.omgandroid I/HelloSmartcard﹕ Retrieve available readers... 01-07 22:52:42.980 9883-9883/com.example.mohanmorpho.omgandroid I/HelloSmartcard﹕ seService.isConnected()=false 01-07 22:52:42.980 9883-9883/com.example.mohanmorpho.omgandroid E/HelloSmartcard﹕ Error occured: java.lang.IllegalStateException: service not connected to system at org.simalliance.openmobileapi.SEService.getReaders(SEService.java:168) at mohanmorpho.omgandroid.MainActivity.btnTest_OnClick(MainActivity.java:83) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at android.view.View$1.onClick(View.java:4268) at android.view.View.performClick(View.java:5217) at android.view.View$PerformClick.run(View.java:20983) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:6117) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

Please advise anything i might be missing or any more information required. Thanks.

krunalindrodiya commented 8 years ago

Same issues also facing me. There is solution for same.