I have a JavaCard with applet which returns simple "HelloWorld". Now I'm trying to send APDU to card from my smartphone.
Basing on Sajedul's respone from here: How to read and write Android NFC tags? I wrote something like this
MainActivity.java
import android.app.PendingIntent;
import android.content.Intent;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import java.io.IOException;
public class MainActivity extends ActionBarActivity {
NfcAdapter mAdapter;
PendingIntent mPendingIntent;
Tag tag;
@Override
protected void onCreate(Bundle savedInstanceState) {
mAdapter = NfcAdapter.getDefaultAdapter(this);
mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onResume(){
mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
}
@Override
public void onPause(){
if(mAdapter != null){
mAdapter.disableForegroundDispatch(this);
}
}
@Override
public void onNewIntent(Intent intent){
getTagInfo(intent);
}
private void getTagInfo(Intent intent){
tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
}
public void doWork(View view) throws IOException {
Tag tagFromIntent = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG);
IsoDep isoDep = IsoDep.get(tagFromIntent);
isoDep.connect();
byte[] SELECT = {
(byte) 0x00, // CLA = 00 (first interindustry command set)
(byte) 0xA4, // INS = A4 (SELECT)
(byte) 0x04, // P1 = 04 (select file by DF name)
(byte) 0x0C, // P2 = 0C (first or only file; no FCI)
(byte) 0x06, // Lc = 6 (data/AID has 6 bytes)
(byte) 0x31, (byte) 0x35,(byte) 0x38,(byte) 0x34,(byte) 0x35,(byte) 0x46 // AID = 15845F
};
byte[] result = isoDep.transceive(SELECT);
}
}
But after instllation on phone, app crashes.
java.lang.RuntimeException: Unable to resume activity {com.example.korek.moja/com.example.korek.moja.MainActivity}: android.app.SuperNotCalledException: Activity {com.example.korek.moja/com.example.korek.moja.MainActivity} did not call through to super.onResume()
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2937)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2966)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2367)
at android.app.ActivityThread.access$700(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.app.SuperNotCalledException: Activity {com.example.korek.moja/com.example.korek.moja.MainActivity} did not call through to super.onResume()
at android.app.Activity.performResume(Activity.java:5452)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2922)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2966)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2367)
at android.app.ActivityThread.access$700(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
Even before applying Sajedul's tips app was crashing on click. What to do to get it working? I'm using SGS4, AndroidStudio and 14443-4b card.
0 comments:
Post a Comment