jnihelp.h頭文件根據(jù)需求自行添加,也可以直接刪除
站在用戶的角度思考問題,與客戶深入溝通,找到海南網(wǎng)站設(shè)計(jì)與海南網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站設(shè)計(jì)制作、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、網(wǎng)絡(luò)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋海南地區(qū)。
#define LOG_TAG "JNIHelp" #include "JNIHelp.h" #include "android/log.h" #include #include #include #include static void getExceptionSummary(JNIEnv* env, jthrowable exception, char* buf, size_t bufLen) { int success = 0; /* get the name of the exception's class */ jclass exceptionClazz = env->GetObjectClass(exception); // can't fail jclass classClazz = env->GetObjectClass(exceptionClazz); // java.lang.Class, can't fail jmethodID classGetNameMethod = env->GetMethodID(classClazz, "getName", "()Ljava/lang/String;"); jstring classNameStr = static_cast if (classNameStr != NULL) { /* get printable string */ const char* classNameChars = env->GetStringUTFChars( classNameStr, NULL); if (classNameChars != NULL) { /* if the exception has a message string, get that */ jmethodID throwableGetMessageMethod = env->GetMethodID( exceptionClazz, "getMessage", "()Ljava/lang/String;"); jstring messageStr = static_cast if (messageStr != NULL) { const char* messageChars = env->GetStringUTFChars( messageStr, NULL); if (messageChars != NULL) { snprintf(buf, bufLen, "%s: %s", classNameChars, messageChars); env->ReleaseStringUTFChars( messageStr, messageChars); } else { env->ExceptionClear(); // clear OOM snprintf(buf, bufLen, "%s: } env->DeleteLocalRef( messageStr); } else { strncpy(buf, classNameChars, bufLen); buf[bufLen - 1] = '\0'; } env->ReleaseStringUTFChars( classNameStr, classNameChars); success = 1; } env->DeleteLocalRef( classNameStr); } env->DeleteLocalRef( classClazz); env->DeleteLocalRef( exceptionClazz); if (! success) { env->ExceptionClear(); snprintf(buf, bufLen, "%s", " } } /* Throw an exception with the specified class and an optional message.*/ int jniThrowException(JNIEnv* env) { jclass exceptionClass; int result = 0; if (env->ExceptionCheck()) { /* TODO: consider creating the new exception with this as "cause" */ char buf[256]; jthrowable exception = env->ExceptionOccurred(); env->ExceptionClear(); if (exception != NULL) { getExceptionSummary(env,exception, buf, sizeof(buf)); //LOGW("Discarding pending exception (%s) to throw %s\n", buf, className); __android_log_print(ANDROID_LOG_INFO, "", "Discarding pending exception (%s) to throw\n",buf); env->DeleteLocalRef(exception); result = -1; } } return result; } |