android在ndk/jni的cc/c ++中获取imei [英] android get imei in cc/c++ for ndk/JNI
本文介绍了android在ndk/jni的cc/c ++中获取imei的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我会尝试使用C/C ++(使用ndk)获取设备的imei
,并使用JNI检索结果.
I would try to get the imei
of a device in C/C++ (using ndk) and retrieve the result with JNI.
const char *res = exec_get_out("service call iphonesubinfo 3");
可以在shell中使用,但不能在我的应用程序中使用
Works in shell, but does not in my application
我在清单中设置了READ_PHONE_STATE
权限.这是针对棉花糖Android系统的(并且我已经接受设置的权限)
I have the READ_PHONE_STATE
permission set in the Manifest. This is targeted for Marshmallow Android (and I have accepted permission in settings)
还有其他解决方案是否可行?如果没有JNI环境,是否不可能?
Is there any other solution that would work or is it not possible without a JNI environment?
推荐答案
检查此
#include <sys/system_properties.h>
//returns the string length of the value.
int ir = __system_property_get("ro.gsm.imei", imei_start);
if(ir > 0)
{
imei_start[15]=0;//strz end
printf("method1 got imei %s len %d\r\n",imei_start,strlen(imei_start));
strcpy(g_imei,imei_start);
}
else
{
printf("method1 imei failed - trying method2\r\n");
//old dumpsys imei getter
char* res = exec_get_out("dumpsys iphonesubinfo");
const char* imei_start_match = "ID = ";
int imei_start_match_len = strlen(imei_start_match);
char* imei_start = strstr(res,imei_start_match);
if(imei_start && strlen(imei_start)>=15+imei_start_match_len)
{
imei_start += imei_start_match_len;
imei_start[15] = 0;
printf("method2 IMEI [%s] len %d\r\n",imei_start,strlen(imei_start));
strcpy(g_imei,imei_start);
}
}
这篇关于android在ndk/jni的cc/c ++中获取imei的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文