소스작성을 했는데 카드인식은 해서 아이디값은 불러오는데
ISODEP 가 문제인거같아요 소스를 작성했는데
뭐가 문제인지좀 봐주세요...
package com.example.nfctocard;
import java.io.Console;
import java.io.IOException;
import java.io.Reader;
import android.support.v7.app.ActionBarActivity;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.p2p.WifiP2pManager.Channel;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.nfc.tech.IsoDep;
import android.nfc.tech.MifareClassic;
import android.nfc.tech.MifareUltralight;
import android.nfc.tech.NfcA;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import util.conversion;
public class MainActivity extends ActionBarActivity {
private NfcAdapter nfcAdapter;
private PendingIntent pendingIntent;
private Toolbar mToolbar;
private NfcAdapter mNfcAdapter;
private TextView tagDesc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tagDesc = (TextView)findViewById(R.id.tagDesc);
nfcAdapter = NfcAdapter.getDefaultAdapter(this);
Intent intent = new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
}
@Override
protected void onPause() {
super.onPause();
if (nfcAdapter != null) {
nfcAdapter.disableForegroundDispatch(this);
}
}
@Override
protected void onResume() {
super.onResume();
if (nfcAdapter != null) {
nfcAdapter.enableForegroundDispatch(this, pendingIntent, null, null);
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
/*===============================================================
* APDU Command *
===============================================================*/
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
IsoDep iso = IsoDep.get(tag);
try {
iso.connect();
// http://nelenkov.blogspot.kr/2012/08/android-secure-element-execution.html
// http://developer.android.com/reference/android/nfc/tech/IsoDep.html
String APDUCommand = "APDU 명령어 입력란";
byte[] result = iso.transceive(util.conversion.hexStringToByteArray(APDUCommand));
// APDU Response Data
String strAnswer = util.conversion.toHexString(result);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*===============================================================
* 디바이스 정보 읽기 *
===============================================================*/
//
// TelephonyManager telephonyManager;
// telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// String simSerialNumber = telephonyManager.getDeviceId();
// tagDesc.setText("simSerialNumber: " + simSerialNumber);
}
void resolveIntent(Intent intent){
String action=intent.getAction();
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) {
Tag productTag=intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
MifareClassic mfc=MifareClassic.get(productTag);
try {
mfc.connect();
boolean auth=false;
auth=mfc.authenticateSectorWithKeyA(0,MifareClassic.KEY_DEFAULT);
if (auth) {
byte[] data=mfc.readBlock(1);
tagDesc.setText("Response: " + util.conversion.toHexString(data));
}
}
catch ( IOException ex) {
ex.printStackTrace();
}
}
else {
tagDesc.setText("No Action ");
}
}
public int sectorToBlock(int sectorIndex) {
if (sectorIndex < 32) {
return sectorIndex * 4;
} else {
return 32 * 4 + (sectorIndex - 32) * 16;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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.getIte
mId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}