gpt4 book ai didi

android - 从 Android 上的 C++ 获取唯一设备标识符

转载 作者:行者123 更新时间:2023-12-02 10:38:37 42 4
gpt4 key购买 nike

我有一个 native android 库,我正尝试使用许可系统保护它。为此,我需要获取当前 Android 设备的唯一标识符。我一直在尝试很多解决方案,但都需要 JAVA 应用程序。

所以我的问题是:是否有可能从 C++ 代码(使用 NDK 或 C++ 嵌入式函数)获取唯一标识符?

问候

最佳答案

这是代码...

std::string getPublicStaticString(JNIEnv *env, const char *className, const char *fieldName) {
jclass clazz = env->FindClass(className);
if (clazz != nullptr) {
jfieldID fid = env->GetStaticFieldID(clazz, fieldName, "Ljava/lang/String;");
if (fid != nullptr) {
jstring GladioReceiver = (jstring) env->GetStaticObjectField(clazz, fid);
jboolean blnIsCopy;
std::string mystr = env->GetStringUTFChars(GladioReceiver, &blnIsCopy);
return mystr;
}
}
return "ERROR";
}

std::string CreateDeviceUniqueID(JNIEnv *env) {
std::string strReturn;
std::string board = getPublicStaticString(env, "android/os/Build", "BOARD");
std::string brand = getPublicStaticString(env, "android/os/Build", "BRAND");
std::string display = getPublicStaticString(env, "android/os/Build", "DISPLAY");
std::string device = getPublicStaticString(env, "android/os/Build", "DEVICE");
std::string manufacturer = getPublicStaticString(env, "android/os/Build", "MANUFACTURER");
std::string model = getPublicStaticString(env, "android/os/Build", "MODEL");
std::string product = getPublicStaticString(env, "android/os/Build", "PRODUCT");

int mod = 10;
int a1 = ((int) board.size()) % mod;
int a2 = ((int) brand.size()) % mod;
int a3 = ((int) display.size()) % mod;
int a4 = ((int) device.size()) % mod;
int a5 = ((int) manufacturer.size()) % mod;
int a6 = ((int) model.size()) % mod;
int a7 = ((int) product.size()) % mod;

strReturn = "35" +
std::to_string(a1) +
std::to_string(a2) +
std::to_string(a3) +
std::to_string(a4) +
std::to_string(a5) +
std::to_string(a6) +
std::to_string(a7);

return strReturn;
}

关于android - 从 Android 上的 C++ 获取唯一设备标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57002105/

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