Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open android settings from QT app(com.android.settings)

I have an android application in QT. I would like to call android settings from a button.

I used this code in Java :

public void usb(View v){
    Intent intent = new Intent();  
    intent.setClassName("com.android.settings", "com.android.settings.DevelopmentSettings");  
    startActivity(intent);  
} 

Is there a way to call android settings using QT C++?

like image 358
Dany19 Avatar asked Jul 29 '14 20:07

Dany19


1 Answers

QAndroidJniObject makes it possible to create JNI objects from Qt C++ code.

For example: to get the activity:

QAndroidJniObject activity =  QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");

For example: to create a new Intent:

QAndroidJniObject intent("android/content/Intent","()V");

You can then step by step translate execute your java code from C++....

To answer your specific question, just copy/paste this code:

QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");   //activity is valid
if ( activity.isValid() )
{
    // Equivalent to Jave code: 'Intent intent = new Intent();'
    QAndroidJniObject intent("android/content/Intent","()V");
    if ( intent.isValid() )
    {
        QAndroidJniObject param1 = QAndroidJniObject::fromString("com.android.settings");
        QAndroidJniObject param2 = QAndroidJniObject::fromString("com.android.settings.DevelopmentSettings");

        if ( param1.isValid() && param2.isValid() )
        {
            // Equivalent to Jave code: 'intent.setClassName("com.android.settings", "com.android.settings.DevelopmentSettings");'
            intent.callObjectMethod("setClassName","(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;",param1.object<jobject>(),param2.object<jobject>());

            // Equivalent to Jave code: 'startActivity(intent);'
            activity.callObjectMethod("startActivity","(Landroid/content/Intent;)V",intent.object<jobject>());
        }
    }
}

...and then vote up! ;-)

like image 147
jpo38 Avatar answered Oct 17 '22 20:10

jpo38