本帖最后由 BabySky716 于 2014-01-04 17:04:48 编辑

解决方案 »

  1.   

    这个是要访问内部类的属性吧,内部类可以看做是类的一个特殊的属性去理解,只是类型是class ,楼主要访问他的属性id,可以在“外部类”Iso7816中写个方法来获取,最后只要在需要的地方通过调用这个方法就可以获取到ID
      

  2.   

    Iso7816 iso = new Iso7816();
    Tag tag = iso.new Tag();
      

  3.   

    Iso7816.java 中添加方法:public ID getTagId(){return new Tag(参数自己加);}NFCard 获取id的时候: ID id = new Iso7816().getTagId();
      

  4.   

    Iso7816.java 中添加方法:public ID getTagId(){return new Tag(参数自己加);}上面那句话报错:This method requires a body instead of a semicolon
    下面那句话报错:Multiple ers at this line
    - Void methods cannot return a 
     value
    - cNow cannot be resolved to a 
     variableNFCard 获取id的时候: ID id = new Iso7816().getTagId();
    报错:
    Multiple ers at this line
    - ID cannot be resolved to a type
    - The method getTagId() is undefined for the type 
     Iso7816
    - The constructor Iso7816() is not visible
      

  5.   

    Iso7816 iso = new Iso7816();
    报错:The constructor Iso7816() is not visible
    Tag tag = iso.new Tag();
    报错:The constructor Iso7816.Tag() is undefinedPS:版主大神能告知QQ号码吗,我把工程传过来给您看。
      

  6.   

    Iso7816 iso = new Iso7816();
    报错:The constructor Iso7816() is not visible
    Tag tag = iso.new Tag();
    报错:The constructor Iso7816.Tag() is undefinedPS:版主大神能告知QQ号码吗,我把工程传过来给您看。我不知道你Iso7816构造函数是怎样的,你改成你的类定义的构造函数就行了。
    Tag也是一样的
      

  7.   

    Iso7816 iso = new Iso7816();
    报错:The constructor Iso7816() is not visible
    Tag tag = iso.new Tag();
    报错:The constructor Iso7816.Tag() is undefinedPS:版主大神能告知QQ号码吗,我把工程传过来给您看。我不知道你Iso7816构造函数是怎样的,你改成你的类定义的构造函数就行了。
    Tag也是一样的Iso7816 iso = new Iso7816();
    报错:The constructor Iso7816() is not visible
    Tag tag = iso.new Tag();
    报错:The constructor Iso7816.Tag() is undefinedPS:版主大神能告知QQ号码吗,我把工程传过来给您看。我不知道你Iso7816构造函数是怎样的,你改成你的类定义的构造函数就行了。
    Tag也是一样的
    版主大人我关注你了,互相关注才能发私信,求QQ号码!!
      

  8.   

    package com.sinpo.xnfc.tech;import java.nio.ByteBuffer;
    import java.util.ArrayList;
    import java.util.Arrays;import android.nfc.tech.IsoDep;import com.sinpo.xnfc.Util;public class Iso7816 {
    public static final byte[] EMPTY = { 0 }; protected byte[] data; protected Iso7816() {
    data = Iso7816.EMPTY;
    } protected Iso7816(byte[] bytes) {
    data = (bytes == null) ? Iso7816.EMPTY : bytes;
    } public boolean match(byte[] bytes) {
    return match(bytes, 0);
    } public boolean match(byte[] bytes, int start) {
    final byte[] data = this.data;
    if (data.length <= bytes.length - start) {
    for (final byte v : data) {
    if (v != bytes[start++])
    return false;
    }
    }
    return true;
    } public boolean match(byte tag) {
    return (data.length == 1 && data[0] == tag);
    } public boolean match(short tag) {
    final byte[] data = this.data;
    if (data.length == 2) {
    final byte d0 = (byte) (0x000000FF & tag);
    final byte d1 = (byte) (0x000000FF & (tag >> 8));
    return (data[0] == d0 && data[1] == d1);
    }
    return false;
    } public int size() {
    return data.length;
    } public byte[] getBytes() {
    return data;
    } @Override
    public String toString() {
    return Util.toHexString(data, 0, data.length);
    } public final static class ID extends Iso7816 {
    public ID(byte[] bytes) {
    super(bytes);
    }
    } public final static class Response extends Iso7816 {
    public static final byte[] EMPTY = {};
    public static final byte[] ERROR = { 0x6F, 0x00 }; // SW_UNKNOWN public Response(byte[] bytes) {
    super((bytes == null || bytes.length < 2) ? Response.ERROR : bytes);
    } public byte getSw1() {
    return data[data.length - 2];
    } public byte getSw2() {
    return data[data.length - 1];
    } public short getSw12() {
    final byte[] d = this.data;
    int n = d.length;
    return (short) ((d[n - 2] << 8) | (0xFF & d[n - 1]));
    } public boolean isOkey() {
    return equalsSw12(SW_NO_ERROR);
    } public boolean equalsSw12(short val) {
    return getSw12() == val;
    } public int size() {
    return data.length - 2;
    } public byte[] getBytes() {
    return isOkey() ? Arrays.copyOfRange(data, 0, size())
    : Response.EMPTY;
    }
    } public final static class BerT extends Iso7816 {
    // tag template
    public static final byte TMPL_FCP = 0x62; // File Control Parameters
    public static final byte TMPL_FMD = 0x64; // File Management Data
    public static final byte TMPL_FCI = 0x6F; // FCP and FMD // proprietary information
    public final static BerT CLASS_PRI = new BerT((byte) 0xA5);
    // short EF identifier
    public final static BerT CLASS_SFI = new BerT((byte) 0x88);
    // dedicated file name
    public final static BerT CLASS_DFN = new BerT((byte) 0x84);
    // application data object
    public final static BerT CLASS_ADO = new BerT((byte) 0x61);
    // application id
    public final static BerT CLASS_AID = new BerT((byte) 0x4F); public static int test(byte[] bytes, int start) {
    int len = 1;
    if ((bytes[start] & 0x1F) == 0x1F) {
    while ((bytes[start + len] & 0x80) == 0x80)
    ++len; ++len;
    }
    return len;
    } public static BerT read(byte[] bytes, int start) {
    return new BerT(Arrays.copyOfRange(bytes, start,
    start + test(bytes, start)));
    } public BerT(byte tag) {
    this(new byte[] { tag });
    } public BerT(short tag) {
    this(new byte[] { (byte) (0x000000FF & (tag >> 8)),
    (byte) (0x000000FF & tag) });
    } public BerT(byte[] bytes) {
    super(bytes);
    } public boolean hasChild() {
    return ((data[0] & 0x20) == 0x20);
    }
    } public final static class BerL extends Iso7816 {
    private final int val; public static int test(byte[] bytes, int start) {
    int len = 1;
    if ((bytes[start] & 0x80) == 0x80) {
    len += bytes[start] & 0x07;
    }
    return len;
    } public static int calc(byte[] bytes, int start) {
    if ((bytes[start] & 0x80) == 0x80) {
    int v = 0; int e = start + bytes[start] & 0x07;
    while (++start <= e) {
    v <<= 8;
    v |= bytes[start] & 0xFF;
    } return v;
    } return bytes[start];
    } public static BerL read(byte[] bytes, int start) {
    return new BerL(Arrays.copyOfRange(bytes, start,
    start + test(bytes, start)));
    } public BerL(byte[] bytes) {
    super(bytes);
    val = calc(bytes, 0);
    } public int toInt() {
    return val;
    }
    } public final static class BerV extends Iso7816 {
    public static BerV read(byte[] bytes, int start, int len) {
    return new BerV(Arrays.copyOfRange(bytes, start, start + len));
    } public BerV(byte[] bytes) {
    super(bytes);
    }
    } public final static class BerTLV extends Iso7816 {
    public static int test(byte[] bytes, int start) {
    final int lt = BerT.test(bytes, start);
    final int ll = BerL.test(bytes, start + lt);
    final int lv = BerL.calc(bytes, start + lt); return lt + ll + lv;
    } public static BerTLV read(Iso7816 obj) {
    return read(obj.getBytes(), 0);
    } public static BerTLV read(byte[] bytes, int start) {
    int s = start;
    final BerT t = BerT.read(bytes, s);
    s += t.size(); final BerL l = BerL.read(bytes, s);
    s += l.size(); final BerV v = BerV.read(bytes, s, l.toInt());
    s += v.size(); final BerTLV tlv = new BerTLV(t, l, v);
    tlv.data = Arrays.copyOfRange(bytes, start, s); return tlv;
    } public static ArrayList<BerTLV> readList(Iso7816 obj) {
    return readList(obj.getBytes());
    } public static ArrayList<BerTLV> readList(final byte[] data) {
    final ArrayList<BerTLV> ret = new ArrayList<BerTLV>(); int start = 0;
    int end = data.length - 3;
    while (start < end) {
    final BerTLV tlv = read(data, start);
    ret.add(tlv); start += tlv.size();
    } return ret;
    } public final BerT t;
    public final BerL l;
    public final BerV v; public BerTLV(BerT t, BerL l, BerV v) {
    this.t = t;
    this.l = l;
    this.v = v;
    } public BerTLV getChildByTag(BerT tag) {
    if (t.hasChild()) {
    final byte[] raw = v.getBytes();
    int start = 0;
    int end = raw.length;
    while (start < end) {
    if (tag.match(raw, start))
    return read(raw, start); start += test(raw, start);
    }
    } return null;
    } public BerTLV getChild(int index) {
    if (t.hasChild()) {
    final byte[] raw = v.getBytes();
    int start = 0;
    int end = raw.length; int i = 0;
    while (start < end) {
    if (i++ == index)
    return read(raw, start); start += test(raw, start);
    }
    } return null;
    }
    } public final static class Tag {
    private final IsoDep nfcTag;
    private ID id; public Tag(IsoDep tag) {
    nfcTag = tag;
    id = new ID(tag.getTag().getId());
    } public ID getID() {
    return id;
    } public Response verify() {
    final byte[] cmd = { (byte) 0x00, // CLA Class
    (byte) 0x20, // INS Instruction
    (byte) 0x00, // P1 Parameter 1
    (byte) 0x00, // P2 Parameter 2
    (byte) 0x02, // Lc
    (byte) 0x12, (byte) 0x34, }; return new Response(transceive(cmd));
    } public Response initPurchase(boolean isEP) {
    final byte[] cmd = {
    (byte) 0x80, // CLA Class
    (byte) 0x50, // INS Instruction
    (byte) 0x01, // P1 Parameter 1
    (byte) (isEP ? 2 : 1), // P2 Parameter 2
    (byte) 0x0B, // Lc
    (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00,
    (byte) 0x00, (byte) 0x11, (byte) 0x22, (byte) 0x33,
    (byte) 0x44, (byte) 0x55, (byte) 0x66, (byte) 0x0F, // Le
    }; return new Response(transceive(cmd));
    } public Response getBalance(boolean isEP) {
    final byte[] cmd = { (byte) 0x80, // CLA Class
    (byte) 0x5C, // INS Instruction
    (byte) 0x00, // P1 Parameter 1
    (byte) (isEP ? 2 : 1), // P2 Parameter 2
    (byte) 0x04, // Le
    }; return new Response(transceive(cmd));
    } public Response readRecord(int sfi, int index) {
    final byte[] cmd = { (byte) 0x00, // CLA Class
    (byte) 0xB2, // INS Instruction
    (byte) index, // P1 Parameter 1
    (byte) ((sfi << 3) | 0x04), // P2 Parameter 2
    (byte) 0x00, // Le
    }; return new Response(transceive(cmd));
    } public Response readRecord(int sfi) {
    final byte[] cmd = { (byte) 0x00, // CLA Class
    (byte) 0xB2, // INS Instruction
    (byte) 0x01, // P1 Parameter 1
    (byte) ((sfi << 3) | 0x05), // P2 Parameter 2
    (byte) 0x00, // Le
    }; return new Response(transceive(cmd));
    } public Response readBinary(int sfi) {
    final byte[] cmd = { (byte) 0x00, // CLA Class
    (byte) 0xB0, // INS Instruction
    (byte) (0x00000080 | (sfi & 0x1F)), // P1 Parameter 1
    (byte) 0x00, // P2 Parameter 2
    (byte) 0x00, // Le
    }; return new Response(transceive(cmd));
    } public Response readData(int sfi) {
    final byte[] cmd = { (byte) 0x80, // CLA Class
    (byte) 0xCA, // INS Instruction
    (byte) 0x00, // P1 Parameter 1
    (byte) (sfi & 0x1F), // P2 Parameter 2
    (byte) 0x00, // Le
    }; return new Response(transceive(cmd));
    }}
    字数有限制,后面一点就发不上来了,