Please nominate your Qt Champions for 2021!

Make Android service using qt 5.7

  • I am using qt 5.7 for android after I create templates and go to AndroidManifest.xml I found this line

    <!-- For adding service(s) please check: -->

    I go to the website and got the code to add the service to my android app and add it after the line above and make a test but it not works I don't see my app in the running service on my android phone
    so what I do wrong or what I should do to make android service to my application
    Thanks in dvance

  • There are some limit when make Android service on Qt

  • @kd_wala First Thanks for your reply
    i try the website you post and follow it and i chose to use my service on demand i add the java class in the link
    and change the packages and edit it to use it in my project when the app start and i press the button to start service that have this code

    void MainWindow::on_pushButton_2_clicked()
        qDebug() << "Is valid" << QAndroidJniObject::isClassAvailable("org/qtproject/example/MyService"); // return true

    i got

    unfortunately services has stopped

    so what should i do now i follow the steps and iam sure that there is no wrong in it ?

  • this what I have reached in my android manifest .xml

    	     <service android:process=":qt" android:name="org.qtproject.example.MyService">
            <!-- android:process=":qt" is needed to force the service to run on a separate process than the Activity -->
                <!-- Application arguments -->
                <!-- Application arguments -->
                <!-- If you are using the same application (.so file) for activity and also for service, then you
                     need to use ** to pass some arguments to your service in order to know which
                     one is which.
                <!-- Application to launch -->
                <meta-data android:name="" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
                <!-- Application to launch -->
                <!-- Ministro -->
                <meta-data android:name="" android:resource="@array/qt_sources"/>
                <meta-data android:name="" android:value="default"/>
                <meta-data android:name="" android:resource="@array/qt_libs"/>
                <meta-data android:name="" android:resource="@array/bundled_libs"/>
                <!-- Ministro -->
                <!-- Deploy Qt libs as part of package -->
                <meta-data android:name="" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
                <meta-data android:name="" android:resource="@array/bundled_in_lib"/>
                <meta-data android:name="" android:resource="@array/bundled_in_assets"/>
                <!-- Deploy Qt libs as part of package -->
                <!-- Run with local libs -->
                <meta-data android:name="" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
                <meta-data android:name="" android:value="/data/local/tmp/qt/"/>
                <meta-data android:name="" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
                <meta-data android:name="" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
                <meta-data android:name="" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
                <!-- Run with local libs -->
                <!--  Messages maps -->
                <meta-data android:value="@string/ministro_not_found_msg" android:name=""/>
                <meta-data android:value="@string/ministro_needed_msg" android:name=""/>
                <meta-data android:value="@string/fatal_error_msg" android:name=""/>
                <!--  Messages maps -->
                <!-- Background running -->
                <meta-data android:name="" android:value="true"/>
                <!-- Background running -->

    please any help or hint what i should do please

  • As i know, Qt & android run in separate thread, so, if your config is correct, i think problem is you should call function start service on Android UI thread, you can check function QtAndroid::runOnAndroidThread of module androidextras

Log in to reply