2011-08-24 5 views

답변

1

NDK는 Java 기반 API를 대체하는 것이 아니라 API를 보완하기위한 것이 아닙니다. Build를 얻으려면 C/C++에서 개인 구현을 찾거나 JNI를 통해 Java로부터 정보를 제공해야합니다.

의사 코드 :

android_main(struct *android_app){ 
    JNIEnv *env = android_app->activity->env; 
    jclass build_class = FindClass(env, "android.os.Build"); 
    jfieldID brand_id = GetStaticFieldID(env, build_class, "BRAND", "Ljava/lang/String;"); 
    jstring brand_obj = (jstring)GetStaticObjectField(env, brand_id); 
} 
+0

감사합니다. C/C++ 구현을 찾을 수 없지만 JNI를 통해 Java에서이 정보를 검색하고 검색 할 수 있습니다. 'JNIEnv *'가 함수 매개 변수이고, 나중에'GetMethodID'와'CallVoidMethod'와 같은 메소드를 호출하는 데 사용되는 예제를 보았습니다. 그러나이 메소드를 호출 할 수있는 원시 메소드의 위치 또는 방법을 모르겠습니다. 이 JNIEnv * 매개 변수는 어디에서 가져올 수 있습니까? –

+1

(예 : 내 순전히 기본 응용 프로그램은 '순수 기본 응용 프로그램에 내 진입 점으로'android_main'을 가지고 있으므로 JNIEnv *를 매개 변수로 사용하는 함수를 호출하는 방법을 잘 모릅니다) –

+0

아, 이것이 문제가 될 것입니다. , 어떤 종류의 정보를 Build에서 찾고 있습니까? –

0

난 당신이 불행하게도이 작업을 수행 할 수 있다고 생각하지 않습니다. VM에서 시작하여 액세스하려는 값을 검색 한 후 JNI를 통해 기본으로 이동할 수 있습니다.

6

이 값은 <sys/system_properties.h>에 정의 된 인터페이스를 통해 네이티브 코드에서 쉽게 얻을 수 있습니다.이 인터페이스는 첫 번째 NDK 릴리스 이후로 사용되었습니다. Java 측에서 사용되는 문자열 식별자를 알아야합니다. 운좋게도 오픈 소스 OS를 사용하면 쉽게 찾을 수 있습니다. 다음은 모델 이름을 가져 오는 작업 예제입니다.

#include <sys/system_properties.h> 

// 
// Public codes are defined in http://developer.android.com/reference/java/lang/System.html#getProperty(java.lang.String). 
// Codes below are defined in https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/os/Build.java. 
// Items with * are intended for display to the end user. 
// 

#define ANDROID_OS_BUILD_VERSION_RELEASE  "ro.build.version.release"   // * The user-visible version string. E.g., "1.0" or "3.4b5". 
#define ANDROID_OS_BUILD_VERSION_INCREMENTAL "ro.build.version.incremental"  // The internal value used by the underlying source control to represent this build. 
#define ANDROID_OS_BUILD_VERSION_CODENAME "ro.build.version.codename"   // The current development codename, or the string "REL" if this is a release build. 
#define ANDROID_OS_BUILD_VERSION_SDK   "ro.build.version.sdk"    // The user-visible SDK version of the framework. 

#define ANDROID_OS_BUILD_MODEL    "ro.product.model"     // * The end-user-visible name for the end product.. 
#define ANDROID_OS_BUILD_MANUFACTURER  "ro.product.manufacturer"   // The manufacturer of the product/hardware. 
#define ANDROID_OS_BUILD_BOARD    "ro.product.board"     // The name of the underlying board, like "goldfish". 
#define ANDROID_OS_BUILD_BRAND    "ro.product.brand"     // The brand (e.g., carrier) the software is customized for, if any. 
#define ANDROID_OS_BUILD_DEVICE    "ro.product.device"     // The name of the industrial design. 
#define ANDROID_OS_BUILD_PRODUCT    "ro.product.name"     // The name of the overall product. 
#define ANDROID_OS_BUILD_HARDWARE   "ro.hardware"      // The name of the hardware (from the kernel command line or /proc). 
#define ANDROID_OS_BUILD_CPU_ABI    "ro.product.cpu.abi"    // The name of the instruction set (CPU type + ABI convention) of native code. 
#define ANDROID_OS_BUILD_CPU_ABI2   "ro.product.cpu.abi2"    // The name of the second instruction set (CPU type + ABI convention) of native code. 

#define ANDROID_OS_BUILD_DISPLAY    "ro.build.display.id"    // * A build ID string meant for displaying to the user. 
#define ANDROID_OS_BUILD_HOST    "ro.build.host" 
#define ANDROID_OS_BUILD_USER    "ro.build.user" 
#define ANDROID_OS_BUILD_ID     "ro.build.id"      // Either a changelist number, or a label like "M4-rc20". 
#define ANDROID_OS_BUILD_TYPE    "ro.build.type"      // The type of build, like "user" or "eng". 
#define ANDROID_OS_BUILD_TAGS    "ro.build.tags"      // Comma-separated tags describing the build, like "unsigned,debug". 

#define ANDROID_OS_BUILD_FINGERPRINT   "ro.build.fingerprint"    // A string that uniquely identifies this build. 'BRAND/PRODUCT/DEVICE:RELEASE/ID/VERSION.INCREMENTAL:TYPE/TAGS'. 


char model_id[PROP_VALUE_MAX]; // PROP_VALUE_MAX from <sys/system_properties.h>. 
int len; 
len = __system_property_get(ANDROID_OS_BUILD_MODEL, model_id); // On return, len will equal (int)strlen(model_id). 
+0

감사합니다. 이것은 정확히 누락 된 정보이며 공개 안드로이드 ndk 문서 어디에서나 명백하거나 보이지 않습니다. 다음은 메소드 서명 및 계약에 관심이있는 경우 소스에 대한 링크입니다. https://android.googlesource.com/platform/bionic/+/android-1.6_r1/libc/include/sys/system_properties.h –

관련 문제