마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 질문입니다. 고수님들 도와주세요.

0 추천

소스작성을 했는데 카드인식은 해서 아이디값은 불러오는데

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

manimata08 (120 포인트) 님이 2015년 8월 24일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...