Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Make Android service using qt 5.7
QtWS25 Last Chance

Make Android service using qt 5.7

Scheduled Pinned Locked Moved Mobile and Embedded
5 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AmrCoderA Offline
    AmrCoderA Offline
    AmrCoder
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • kd_walaK Offline
      kd_walaK Offline
      kd_wala
      wrote on last edited by
      #2

      There are some limit when make Android service on Qt

      • the activities & service(s) must run on a different process.
      • it is not possible (yet (hopefully)) to debug the services in QtCreator. This feature will take some time to implement it, therefore I’ll not hold my breath for it, check QTCREATORBUG-16886
        For more detail, I suggest you check post of KDAB blog, i think it will help you
        https://www.kdab.com/qt-android-create-android-service-using-qt/
      AmrCoderA 1 Reply Last reply
      1
      • kd_walaK kd_wala

        There are some limit when make Android service on Qt

        • the activities & service(s) must run on a different process.
        • it is not possible (yet (hopefully)) to debug the services in QtCreator. This feature will take some time to implement it, therefore I’ll not hold my breath for it, check QTCREATORBUG-16886
          For more detail, I suggest you check post of KDAB blog, i think it will help you
          https://www.kdab.com/qt-android-create-android-service-using-qt/
        AmrCoderA Offline
        AmrCoderA Offline
        AmrCoder
        wrote on last edited by
        #3

        @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 ?

        1 Reply Last reply
        0
        • AmrCoderA Offline
          AmrCoderA Offline
          AmrCoder
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • kd_walaK Offline
            kd_walaK Offline
            kd_wala
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved