Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 9 Fix #435

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Android 9 Fix #435

wants to merge 2 commits into from

Conversation

boedy
Copy link

@boedy boedy commented Mar 11, 2019

Background mode is not working for android 9. As it would not launch the Foreground service.

Based on android documentation FOREGROUND_SERVICE permission is required:

Note: Apps that target Android 9 (API level 28) or higher and use foreground services must request the FOREGROUND_SERVICE permission. This is a normal permission, so the system automatically grants it to the requesting app.

If an app that targets API level 28 or higher attempts to create a foreground service without requesting FOREGROUND_SERVICE, the system throws a SecurityException.
source

Also the service was not added correctly to the AndroidManifest.xml

ebhsgit added a commit to ebhsgit/cordova-plugin-background-mode that referenced this pull request May 6, 2019
FOREGROUND_SERVICE
 - https://developer.android.com/guide/components/services
 - katzer#435

REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
 - To request user permission to ignore battery optimization
@okhiroyuki
Copy link

Please Merge it!!

@RafaelKr
Copy link

A merge would be appreciated!

@okhiroyuki Until this is merged you can add the following snippet to the Android platform section in your config.xml:

<config-file parent="/*" target="AndroidManifest.xml">
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
</config-file>

Full structure like this:

<widget id="com.example.app" version="1.0.0">
    [...]
    <platform name="android">
        <config-file parent="/*" target="AndroidManifest.xml">
            <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
        </config-file>
        [...]
    </platform>
    [...]
</widget>

@okhiroyuki
Copy link

@RafaelKr Thank you. It's a nice snippet!!

@danielehrhardt
Copy link

If i implement this Code it is working fine.
#436 (comment)

@ZaLiTHkA
Copy link

ZaLiTHkA commented Oct 29, 2019

quick note: as per this comment by @martin-dufka, I had to include an entry in my config.xml for two permissions before I got this to work on my Xiaomi Mi Mix 2 with LineageOS 16.0 (Android 9.0.0):

  • android.permission.FOREGROUND_SERVICE
  • android.permission.WAKE_LOCK

can anyone else confirm this behaviour?

@asoap
Copy link

asoap commented Nov 5, 2019

To add more information. I also had to add the WAKE_LOCK permission. I was also getting a "unbound prefix" error when I was trying to do the above work around.

To fix that I followed these instructions:
dpa99c/cordova-custom-config#24

The xmlns:android="http://schemas.android.com/apk/res/android" attribute should be added to the root tag inside the config.xml if you want to use .

@manstie
Copy link

manstie commented Nov 9, 2021

+1 to merging this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants