Android 发送十六进制byte的问题 androidjnistringbyte 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以用这个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));} 谢谢 最后我重写了jni发送接口,改为发送byte[]在jni里将jbyteArray转为jbyte;再发送就不出错了 gallery 循环现实图片。 新手做的一款小App,短信轰炸鸡(可以使用飞信) ExpandableListView 拉动或关闭group,child被刷新了!!!求救 通过action启动server问题 关于RadioGroup 里面的RadioButton activity跳转时,怎么使用字符串作为id跳转? 新人求帮助、、 android自动打包 这种效果怎么实现 AS如何从MainActivity中传一个我从文本框中获取的值,到我的自定义类中 如何隐藏 Activity 的标题栏 android菜鸟求教eclipse创建avd问题
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));
}