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: https://wiki.qt.io/AndroidServices -->
    

    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()
    {
        //org.qtproject.example
        QAndroidJniObject::callStaticMethod<void>("org/qtproject/example/MyService",
                                                      "startMyService",
                                                      "(Landroid/content/Context;)V",
                                                      QtAndroid::androidActivity().object());
        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 *android.app.arguments* to pass some arguments to your service in order to know which
                     one is which.
                -->
    
                <!-- Application to launch -->
                <meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
                <!-- Application to launch -->
    
                <!-- Ministro -->
                <meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
                <meta-data android:name="android.app.repository" android:value="default"/>
                <meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
                <meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
                <!-- Ministro -->
    
                <!-- Deploy Qt libs as part of package -->
                <meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
                <meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
                <meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
                <!-- Deploy Qt libs as part of package -->
    
                <!-- Run with local libs -->
                <meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
                <meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
                <meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
                <meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
                <meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
                <!-- Run with local libs -->
    
                <!--  Messages maps -->
                <meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
                <meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
                <meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
                <!--  Messages maps -->
    
    
                <!-- Background running -->
                <meta-data android:name="android.app.background_running" android:value="true"/>
                <!-- Background running -->
            </service>
    

    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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.