Android hdid (#822)

* get ANDROID_ID

* make it more complicated
This commit is contained in:
stonedDiscord 2022-07-23 17:19:40 +02:00 committed by GitHub
parent 0519abab03
commit b0a958e744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -5,6 +5,10 @@
#include <stdio.h> #include <stdio.h>
#ifdef ANDROID
#include <QtAndroidExtras/QtAndroid>
#endif
QString get_hdid(); QString get_hdid();
#endif // HARDWARE_FUNCTIONS_H #endif // HARDWARE_FUNCTIONS_H

View File

@ -38,6 +38,16 @@ QString get_hdid()
CloseHandle(hToken); CloseHandle(hToken);
return returnHDID; return returnHDID;
} }
#elif defined(ANDROID)
QString get_hdid()
{
QAndroidJniObject appctx = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;").callObjectMethod("getApplicationContext","()Landroid/content/Context;");
QAndroidJniObject androidId = QAndroidJniObject::callStaticObjectMethod("android/provider/Settings$Secure","getString",
"(Landroid/content/ContentResolver;Ljava/lang/String;)Ljava/lang/String;",
appctx.callObjectMethod("getContentResolver", "()Landroid/content/ContentResolver;").object<jobject>(),
QAndroidJniObject::fromString("android_id").object<jstring>());
return androidId.toString();
}
#elif QT_VERSION < QT_VERSION_CHECK(5, 11, 0) #elif QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
#if (defined(LINUX) || defined(__linux__)) #if (defined(LINUX) || defined(__linux__))