2015-09-28 130 views
0

我怎樣才能通過Qt從android打開位置設置?打開位置設置安卓與QT

我已經嘗試過這一點,我可以順利打開的設置,而不是位置設置:

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>()); 
     } 
    } 

我甚至已經改變了參數2爲「android.settings.LOCATION_SOURCE_SETTINGS」,因爲它是在寫Android開發者頁面 - 但沒有任何成功。

有人知道該怎麼做嗎? 謝謝!

回答

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>()); 
    } 
}