NDK 获取android的imei和serial number
生活随笔
收集整理的這篇文章主要介紹了
NDK 获取android的imei和serial number
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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 <sys/system_properties.h> void getAndroidDeviceID_Serial(char *deviceID)//serial number {__system_property_get("ro.serialno",deviceID); }
轉載于:https://www.cnblogs.com/273809717/archive/2013/02/21/2921058.html
總結
以上是生活随笔為你收集整理的NDK 获取android的imei和serial number的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Simulated Annealing(
- 下一篇: XP系统安装SQL2000企业版开启14