立即注册
查看: 2236|回复: 1

[MTK软件原创] apk中中读写nvram

已绑定手机
已实名认证
发表于 2016-11-7 15:00:01 | 显示全部楼层 |阅读模式 来自 广东省深圳市
[DESCRIPTION]

apk中读写nvram

[SOLUTION]

nvram中LID对应的结构体如:
typedefstruct
{
intuid;
}NVRAM_AMOI_TEST_STRUCT;
demo code:
//将int型转化成byte数组
private static byte[] getBytes(int data){
byte[] bytes = new byte[4];
bytes[0] = (byte)(data&0xff);
bytes[1] = (byte)((data&0xff00)>>8);
bytes[2] = (byte)((data&0xff0000)>>16);
bytes[3] = (byte)((data&0xff000000)>>24);
return bytes;
}
//将byte数组转换成整型
public static int byte2int(byte[] res) {
int targets = (res[0] & 0xff) | ((res[1] << 8) & 0xff00)| ((res[2] << 24)
>>> 8) | (res[3] << 24);
return targets;
}
//向nvram中写数据
public void writeData() {
IBinderbinder=ServiceManager.getService("NvRAMAgent");
NvRAMAgentagent=NvRAMAgent.Stub.asInterface(binder);
int n = 10;
byte[] buff = new byte[]{0,0,0,0};
byte[] by = getBytes(n);
for(int i=0;i<4;i++
write_buff = by;

try{
intflag=agent.writeFile(file_lid,write_buff);
if(flag>0){
System.out.println("write success");
}else{
System.out.println("write failed");
}
}catch(RemoteExceptione){
e.printStackTrace();
}
}
//从nvram中读取数据
public void readData() {
IBinderbinder=ServiceManager.getService("NvRAMAgent");
NvRAMAgentagent=NvRAMAgent.Stub.asInterface(binder);
byte[] buff = null;
try {
buff = agent.readFile(file_lid);// read buffer from nvram
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(i=0;i<buff.length;i++){
System.out.println("i:"+buff);

}
int b = byte2int(temp);
System.out.println("b:"+b);
}


发表于 2016-11-7 15:59:05 | 显示全部楼层 来自 江苏省苏州市
学习学习
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

合作/建议

TEL: 19168984579

工作时间:
周一到周五 9:00-11:30 13:30-19:30
  • 扫一扫关注公众号
  • 扫一扫打开小程序
Copyright © 2013-2024 一牛网 版权所有 All Rights Reserved. 帮助中心|隐私声明|联系我们|手机版|粤ICP备13053961号|营业执照|EDI证
在本版发帖搜索
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表