zoukankan      html  css  js  c++  java
  • 获取Android版本

    JAVA:

    摘自http://stackoverflow.com/questions/3423754/retrieving-android-api-version-programmatically

    从1.6开始,

    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    
    if (currentapiVersion >= android.os.Build.VERSION_CODES.FROYO){
        // Do something for froyo and above versions
    } else{
        // do something for phones running an SDK before froyo
    }
    

     相关代号宏:

    http://developer.android.com/reference/android/os/Build.VERSION.html#SDK_INT

    http://developer.android.com/reference/android/os/Build.VERSION_CODES.html

    JNI C/C++:

    摘自:http://stackoverflow.com/questions/10196361/how-to-check-the-device-running-api-level-using-c-code-via-ndk

     1 // Based on article here:
     2     //   http://android-developers.blogspot.co.uk/2011/09/androids-http-clients.html
     3     // Which references the issue documented here:
     4     //   http://code.google.com/p/android/issues/detail?id=2939
     5     // We need to set "http.keepAlive" to "false" if running an OS version earlier than Froyo (API Level 8)
     6 
     7     if ((*env)->ExceptionCheck(env))
     8         return false; // already got an exception pending
     9 
    10     bool success = true;
    11 
    12     // VERSION is a nested class within android.os.Build (hence "$" rather than "/")
    13     jclass versionClass = (*env)->FindClass(env, "android/os/Build$VERSION");
    14     if (NULL == versionClass)
    15         success = false;
    16 
    17     jfieldID sdkIntFieldID = NULL;
    18     if (success)
    19         success = (NULL != (sdkIntFieldID = (*env)->GetStaticFieldID(env, versionClass, "SDK_INT", "I")));
    20 
    21     jint sdkInt = 0;
    22     if (success)
    23     {
    24         sdkInt = (*env)->GetStaticIntField(env, versionClass, sdkIntFieldID);
    25         __android_log_print(ANDROID_LOG_VERBOSE, TAG, "sdkInt = %d", sdkInt);
    26     }
    27 
    28     if (success && sdkInt < 8)
    29     {
    30         jclass systemClass = (*env)->FindClass(env, "java/lang/System");
    31         if (NULL == systemClass)
    32             success = false;
    33 
    34         jmethodID setPropertyMethodID = NULL;
    35         if (success)
    36             success = (NULL != (setPropertyMethodID = (*env)->GetStaticMethodID(env, systemClass, "setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;")));
    37 
    38         jstring propString = NULL;
    39         if (success)
    40             success = (NULL != (propString = (*env)->NewStringUTF(env, "http.keepAlive")));
    41 
    42         jstring valueString = NULL;
    43         if (success)
    44             success = (NULL != (valueString = (*env)->NewStringUTF(env, "false")));
    45 
    46         jobject oldValueString = NULL;
    47         if (success)
    48         {
    49             __android_log_print(ANDROID_LOG_VERBOSE, TAG, "Disabling http.keepAlive");
    50              oldValueString = (*env)->CallStaticObjectMethod(env, systemClass, setPropertyMethodID, propString, valueString);
    51         }
    52 
    53         // cleanup
    54         (*env)->DeleteLocalRef(env, propString);
    55         (*env)->DeleteLocalRef(env, valueString);
    56         (*env)->DeleteLocalRef(env, oldValueString);
    57         (*env)->DeleteLocalRef(env, systemClass);
    58     }
    59 
    60     // cleanup
    61     (*env)->DeleteLocalRef(env, versionClass);
    62 
    63     return success;
  • 相关阅读:
    快速排序算法C++实现[评注版]
    浮躁的程序员
    扬长避短使用Windbg和Visual Studio高效调试调试你的代码
    程序员,代码,理想,老男孩
    Windows Server 2008 R2 如何启动kernel dbg进行双机内核调试『续bcdedit 用法详解』
    Windows Server 2008 R2 如何启动kernel dbg进行双机内核调试『配置详解』
    忙着活或忙着死[转]
    SQL2005使用游标的实例(SBO中计算到期应收账款)
    C#编写的Windows计算器源代码
    请登录真正的BBS
  • 原文地址:https://www.cnblogs.com/mushui/p/3323767.html
Copyright © 2011-2022 走看看