从QT app(com.android.settings)打开android设置

前端之家收集整理的这篇文章主要介绍了从QT app(com.android.settings)打开android设置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在QT有一个 Android应用程序.
我想从一个按钮调用android设置.

我在Java中使用了这段代码

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

有没有办法使用QT C调用android设置?

解决方法

QAndroidJniObject可以从Qt C代码创建JNI对象.

例如:获取活动:

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

例如:创建一个新的Intent:

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

然后你可以一步一步地从C语言中执行你的java代码….

要回答您的具体问题,只需复制/粘贴此代码

QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative","()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>());
        }
    }
}

……然后投票!

猜你在找的Android相关文章