編輯:關於Android編程
自檢程序寫在so裡
主要代碼
在文件頭中導入
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #include#include #include #include #endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) extern "C" { JNIEXPORT jint JNICALL Java_org_cocos2dx_cpp_AppActivity_checkAPK(JNIEnv *env, jclass jcl, jobject context_object) { jclass context_class = env->GetObjectClass(context_object); //context.getPackageManager() jmethodID methodId = env->GetMethodID(context_class, "getPackageManager", "()Landroid/content/pm/PackageManager;"); jobject package_manager_object = env->CallObjectMethod(context_object, methodId); if (package_manager_object == NULL) { __android_log_print(ANDROID_LOG_INFO, "JNITag","getPackageManager() Failed!"); return NULL; } //context.getPackageName() methodId = env->GetMethodID(context_class, "getPackageName", "()Ljava/lang/String;"); jstring package_name_string = (jstring)env->CallObjectMethod(context_object, methodId); if (package_name_string == NULL) { __android_log_print(ANDROID_LOG_INFO, "JNITag","getPackageName() Failed!"); return NULL; } env->DeleteLocalRef(context_class); //PackageManager.getPackageInfo(Sting, int) jclass pack_manager_class = env->GetObjectClass(package_manager_object); methodId = env->GetMethodID(pack_manager_class, "getPackageInfo", "(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;"); env->DeleteLocalRef(pack_manager_class); jobject package_info_object = env->CallObjectMethod(package_manager_object, methodId, package_name_string, 64); if (package_info_object == NULL) { __android_log_print(ANDROID_LOG_INFO, "JNITag","getPackageInfo() Failed!"); return NULL; } env->DeleteLocalRef(package_manager_object); //PackageInfo.signatures[0] jclass package_info_class = env->GetObjectClass(package_info_object); jfieldID fieldId = env->GetFieldID(package_info_class, "signatures", "[Landroid/content/pm/Signature;"); env->DeleteLocalRef(package_info_class); jobjectArray signature_object_array = (jobjectArray)env->GetObjectField(package_info_object, fieldId); if (signature_object_array == NULL) { __android_log_print(ANDROID_LOG_INFO, "JNITag","PackageInfo.signatures[] is null"); return NULL; } jobject signature_object = env->GetObjectArrayElement(signature_object_array, 0); env->DeleteLocalRef(package_info_object); //Signature.toCharsString() jclass signature_class = env->GetObjectClass(signature_object); methodId = env->GetMethodID(signature_class, "hashCode", "()I"); env->DeleteLocalRef(signature_class); int signature_string = env->CallIntMethod(signature_object, methodId); HelloWorld::hashCode = signature_string; return signature_string; } } #endif
我們先來看一張圖,它清晰的說明了整個Android系統的啟動流程,參考Android內核開發:圖解Android系統的啟動過程。第一階段:Android設備上電後,首先會
Android Handler消息機制,在Android中扮演了很重要的角色。通過Android Handler,能夠實現延遲處理、子線程更新主線程界面等功能。(Andr
1 背景今天突然想起之前在上家公司(做TV與BOX盒子)時有好幾個人問過我關於Android的Context到底是啥的問題,所以就馬上要誕生這篇文章。我們平時
話不多說先看今天的實現的效果:相信這種效果很多項目都會用到,今天就講講利用RecycleView來實現他,博主把此篇文章定位初級篇,可能因為這確實很簡單,所以我要更要講的