解决方案 »

  1.   

    可以用这个decodeToString函数转换。public int hexToInt(byte b) throws Exception {
    if (b >= '0' && b <= '9') {
    return (int)b - '0';
    }
    if (b >= 'a' && b <= 'f') {
    return (int)b + 10 - 'a';
    }
    if (b >= 'A' && b <= 'F') {
    return (int)b + 10 - 'A';
    }
    throw new Exception("invalid hex");
    }
    public byte[] decodeToBytes(String hexString) {
    byte[] hex = hexString.getBytes();
    if ((hex.length % 2) != 0) {
    return null;
    }
    byte[] ret = new byte[hex.length / 2];
    int j = 0;
    int i = 0;
    try {
         while (i < hex.length) {
         byte hi = hex[i++];
         byte lo = hex[i++];
         ret[j++] = (byte)((hexToInt(hi) << 4) | hexToInt(lo));
         }
    } catch (Exception e) {
    e.printStackTrace();
    return null;
    }
    return ret;
    }
    public String decodeToString(String hexString) {
    return new String(decodeToBytes(hexString));
    }
      

  2.   

    谢谢 最后我重写了jni发送接口,改为发送byte[]在jni里将jbyteArray转为jbyte;再发送就不出错了