gpt4 book ai didi

java - 通过纯原生 Android 应用检索 android.os.Build.... 系统属性

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:01:10 27 4
gpt4 key购买 nike

我有一个纯原生的 Android NDK 应用程序,需要检索以下值:android.os.Build.MODEL

不幸的是,我找不到很好的例子来说明如何去做?

最佳答案

这些值很容易通过 <sys/system_properties.h> 中定义的接口(interface)在 native 代码中获取,自第一个 NDK 版本发布以来就一直存在。您只需要知道 Java 端使用的字符串标识符即可。幸运的是,有了开源操作系统,我们可以很容易地找到这些。这是一个检索模型名称的工作示例。

#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).

关于java - 通过纯原生 Android 应用检索 android.os.Build.... 系统属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7183627/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com