在iccid没有字母的 时候可以用如下代码
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
iccid = tm.getSimSerialNumber();
但有字母的时候,获取不到20位,在硬件小哥的建议下使用at命令。一开始苦于找不到at的串口,后来直接把4g模组给拆下来,对比后发现少了5个串口,然后一个个试就成功了,以下是实现代码
void Receive(String file) {
RandomAccessFile localRandomAccessFile = null;
try {
localRandomAccessFile = new RandomAccessFile(file, "r");
byte[] arrayOfByte = new byte[1024];
int readSize = 0;
while ((readSize = localRandomAccessFile.read(arrayOfByte)) == -1) {
}
String response = new String(arrayOfByte).substring(0, readSize);
LogUtils.e("re:"+response);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
void Send(String file, String cmd){
RandomAccessFile localRandomAccessFile = null;
try {
localRandomAccessFile = new RandomAccessFile(file, "rw");
localRandomAccessFile.writeBytes(cmd + "\r\n");
localRandomAccessFile.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
读写方法只用来测试,根据业务还可以优化
String com = "/dev/ttyUSB3";
Send(com,"at+qccid");
Receive(com);
不同4g模组ccid的指令可能不同,我在网上看的就和我这个不一样,可以测试一下,我这边有模组的文档还是比较好的
后面两个不完全的就是用安卓接口获取的,可以看到从英文f后都被过滤了