概述
1,获取imei
int setAndroidDeviceID(JNIEnv *env, jobject obj,jobject mContext)
{
if(mContext == 0){
return -1;
}
jclass cls_context = (*env)->FindClass(env, "android/content/Context");
if(cls_context == 0){
return -1;
}
jmethodID getSystemService = (*env)->GetMethodID(env, cls_context, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");
if(getSystemService == 0){
return -1;
}
jfieldID TELEPHONY_SERVICE = (*env)->GetStaticFieldID(env, cls_context, "TELEPHONY_SERVICE", "Ljava/lang/String;");
if(TELEPHONY_SERVICE == 0){
return -1;
}
jstring str = (*env)->GetStaticObjectField(env, cls_context, TELEPHONY_SERVICE);
jobject telephonymanager = (*env)->CallObjectMethod(env, mContext, getSystemService, str);
if(telephonymanager == 0){
return -1;
}
jclass cls_tm = (*env)->FindClass(env, "android/telephony/TelephonyManager");
if(cls_tm == 0){
return -1;
}
jmethodID getDeviceId = (*env)->GetMethodID(env, cls_tm, "getDeviceId", "()Ljava/lang/String;");
if(getDeviceId == 0){
return -1;
}
jstring deviceid = (*env)->CallObjectMethod(env, telephonymanager, getDeviceId);
DP_IMIE = (*env)->GetStringUTFChars(env, deviceid, 0);
return 0;
}
2,获取serial number
#include
void getAndroidDeviceID_Serial(char *deviceID)//serial number
{
__system_property_get("ro.serialno",deviceID);
}
最后
以上就是正直招牌为你收集整理的android 获取serialno_NDK 获取android的imei和serial number的全部内容,希望文章能够帮你解决android 获取serialno_NDK 获取android的imei和serial number所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复