Start android service at boot time



  • Hi,
    I have problem with implement starting the android service at boot time.
    I used code from this url: https://github.com/KDAB/android

    And my code: https://ufile.io/r7lfm
    Service is not starting.
    What's wrong with my code?


  • Moderators

    @Montjet
    This doesn't make much sense:

    <receiver android:name=".MyActivity">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
    </receiver>
    

    You should rather connect this to a BroadcastReceiver class. Also you need to specify the android.permission.RECEIVE_BOOT_COMPLETED in your manifest

    I guess you have the corresponding warnings/errors in your logcat.

    Take a look at:
    https://www.kdab.com/qt-android-create-android-service-using-qt/



  • You should rather connect this to a BroadcastReceiver class. Also you need to specify the android.permission.RECEIVE_BOOT_COMPLETED in your manifest
    

    I specified this permission - 3 line.

    This doesn't make much sense:
    
    <receiver android:name=".MyActivity">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
    </receiver>
    

    MyActivity extends BroadcastReceiver class.

    #edit
    Logcat log:

    D/PackageManager(  848): scan package: /data/app/com.kdab.training-1 , start at: 39745ms.
    
    D/PackageManager(  848): Parsing: /data/app/com.kdab.training-1
    
    I/PackageManager(  848): Linking native library dir for /data/app/com.kdab.training-1
    
    I/PackageManager(  848): Perform pre-dex opt for package: com.kdab.training
    
    D/PackageManager(  848): scan package: /data/app/com.kdab.training-1 , end at: 39925ms. elapsed time = 180ms.
    

    And nothing more.

    #edit2
    I found error:

    W/PackageParser(  846): Unknown element under <application>: uses-permission at /data/app/com.kdab.training-1/base.apk Binary XML file line #153
    

  • Moderators

    @Montjet said in Start android service at boot time:

    MyActivity extends BroadcastReceiver class.

    oh k.

    anyway. There must be more than 5 lines in the logcat ouput.
    How are you testing exactly?

    What API version are you building against and also executing on?

    Since Android 7.0 (API 24) some broadcast receivers must to be registered from code.
    https://developer.android.com/guide/components/broadcast-exceptions
    Seems android.intent.action.BOOT_COMPLETED is not part of it, but it is also named differently: ACTION_BOOT_COMPLETED



  • @raven-worx said in Start android service at boot time:

    anyway. There must be more than 5 lines in the logcat ouput.
    How are you testing exactly?

    Command: "./adb -d logcat > log.txt".
    I included only logs containing "com.kdab.training".

    @raven-worx said in Start android service at boot time:

    What API version are you building against and also executing on?

    API level 27.
    Android 5.1 Lollipop.
    SDK Version: 26.1.1.
    NDK Version: 16.1.4479499.
    Qt: 5.11.2.

    #edit
    I changed API level to 22, but service still doesn't start.

    #edit2
    New warning:

    W/PackageManager( 2573): Failure retrieving resources for com.kdab.training: Resource ID #0x0
    

    #edit3
    Application is tested on phone with installed MIUI.
    For some reason application have not permission to autostart - startup manager, so RECEIVE_BOOT_COMPLETED permission still is not granted ;/


Log in to reply
 

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