如何通过Qt从android打开位置设置?
我已经尝试了这个,我可以成功打开设置,但不能打开位置设置:
QAndroidJniObject intent("android/content/Intent","()V");
if ( intent.isValid() )
{
QAndroidJniObject param1 = QAndroidJniObject::fromString("com.android.settings");
QAndroidJniObject param2 = QAndroidJniObject::fromString("com.android.settings.Settings");
if ( param1.isValid() && param2.isValid() )
{
intent.callObjectMethod("setClassName","(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;",param1.object<jobject>(),param2.object<jobject>());
activity.callObjectMethod("startActivity","(Landroid/content/Intent;)V",intent.object<jobject>());
}
}
我甚至已经将param2更改为&#34; android.settings.LOCATION_SOURCE_SETTINGS&#34;因为它写在Android Developer页面上 - 但没有任何成功。
有人知道怎么做吗? 谢谢!
答案 0 :(得分:0)
我找到了解决方案!
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
if ( activity.isValid() )
{
qDebug() << "activity.isValid()";
QAndroidJniObject param = QAndroidJniObject::fromString("android.settings.LOCATION_SOURCE_SETTINGS");
if (param.isValid() )
{
QAndroidJniObject intent("android/content/Intent","(Ljava/lang/String;)V", param.object<jstring>());
activity.callObjectMethod("startActivity","(Landroid/content/Intent;)V",intent.object<jobject>());
}
}
答案 1 :(得分:0)
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
if ( activity.isValid() )
{
QAndroidJniObject param = QAndroidJniObject::fromString("android.settings.LOCATION_SOURCE_SETTINGS");
if (param.isValid() )
{
QAndroidJniObject intent("android/content/Intent","(Ljava/lang/String;)V", param.object<jstring>());
activity.callMethod<void>("startActivity","(Landroid/content/Intent;)V", intent.object<jobject>());
}
}