Giter VIP home page Giter VIP logo

cordova-plugin-foreground-service's Introduction

cordova-plugin-foreground-service npm version

NOTE: This plugin does not on its own allow the user to execute javascript while the app is in the background. This must be accompanied by another plugin that will create a background process that will give the application background cycles. This plugin mainly exists to solve the problem outlined here. An app will have restricted background processing if it is not considered a "foreground app" for android API 26+ and will prevent background pluggins from functioning properly. With this plugin your application will be a foreground app and let your background services run properly. This plugin may also help with android doze where an application may not run in the background unless it also has a foreground process. Do not expect this plugin on its own to allow your app to execute javascript while in the background.


This plugin allows for android devices to continue running services in the background, using a foreground ongoing notification. This is targeted towards use with plugins such as 'cordova-geolocation' that will not run while the app is in the background on android API 26+.


Requirements

  • cordova-android version >= 7.0.0
  • android-sdk api >= 26

NOTE: Using cordova version >= 8.0.0 is recommended.


Setup and Usage

Install

cordova plugin add cordova-plugin-foreground-service

#or

cordova plugin add https://github.com/DavidBriglio/cordova-plugin-foreground-service

Start Method

To enable the foreground service, call the start method:

cordova.plugins.foregroundService.start('Notification Title', 'Notification Text', 'drawable-icon-name', [notification importance], [notification id]);

// High priority with notification id 10
// ('myicon.png' is in the 'res/drawable' folder)
cordova.plugins.foregroundService.start('GPS Running', 'Background Service', 'myicon', 3, 10);

// Notification id is optional
cordova.plugins.foregroundService.start('GPS Running', 'Background Service', 'myicon', 3);

// Notification importance is optional, the default is 1 - Low (no sound or vibration)
cordova.plugins.foregroundService.start('GPS Running', 'Background Service', 'myicon');

// Icon is optional, but will use a 'star' icon as the default
cordova.plugins.foregroundService.start('GPS Running', 'Background Service');

Stop Method

To disable the foreground service, call the stop method:

cordova.plugins.foregroundService.stop();

Parameters

Icon

The drawable icon can be any drawable image that exists in the resource folder. This means you must copy the icon you want to use into the platforms/android/app/src/main/res/drawable folder set. If no icon can be found using the icon name parameter, a default star icon will be used.

NOTE: The normal android drawable (R.drawable) icons are not available for use as icons. You cannot reference these icons through the start icon parameter. Include your icon manually in the folders mentioned above.

Notification ID

The notification id is a customizable integer that is used to reference the notification that will be launched. This is customizable to avoid conflicting with any other notifications. If this is not included, a default id will be used.

Notification Importance

Notification importance dictates how the notification is initially presented:

Value Importance Description
1 IMPORTANCE_LOW Does not make a sound or heads-up display. (Default)
2 IMPORTANCE_DEFAULT Makes a sound, but no heads-up display.
3 IMPORTANCE_HIGH Makes a sound and heads-up display.

Questions?

Please feel free to open an issue or make a pull request!


License

MIT - Please see the LICENSE file for details.


David Briglio (2018)

cordova-plugin-foreground-service's People

Contributors

arielaleksandrus avatar davidbriglio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cordova-plugin-foreground-service's Issues

BLE scan beacon for temperature

Hi!
I'im deploying an app ( platform Android, ionic/angular/Cordova) . In this app i need to execute a routine every one minute to read a beacon ble temperature. Qhen the app goes in inactive state the BLERequestscan dont'return any value.
So i've found this plugin but i've some problem to use it.

I put the start service before my scan function and view the notification, but the scan function don't return any value.

Can you help me?

Monica

Foreground service does not work on Android 10

I have successfully implemented this plugin for Android 8 and Android 9 to let my Ionic app stream music while the phone is locked. The music keeps playing without interruptions.

Now users with Android 10 phones are complaining that the audio drops out after 5 minutes. I am able to confirm that on e.g. Nokia 6.3 and Samsung A20 with Android 10.

Is there a solution to make this plugin work on Android 10?

I added this line to my config.xml (under the tag <platform name="android">) without success:

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/uses-permission" xmlns:android="http://schemas.android.com/apk/res/android"> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> </edit-config>

Keep process alive when kill the app

first, this not a issue with the plugin.
When the app is in background, it work correctly. But I need the process alive when app is killed.
In native is easy but I don't know how do it in cordova.

Not allowed to delete channel foreground.service.channel with a foreground service (With a solution)

Describe the bug

FATAL EXCEPTION: main
    Process: live.nlabs.bible, PID: 16338
    java.lang.RuntimeException: Unable to start service com.davidbriglio.foreground.ForegroundService@6aefd8c with Intent { act=start cmp=live.nlabs.bible/com.davidbriglio.foreground.ForegroundService (has extras) }: java.lang.SecurityException: Not allowed to delete channel foreground.service.channel with a foreground service
    	at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5261)
    	at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2447)
    	at android.os.Handler.dispatchMessage(Handler.java:106)
    	at android.os.Looper.loopOnce(Looper.java:226)
    	at android.os.Looper.loop(Looper.java:313)
    	at android.app.ActivityThread.main(ActivityThread.java:8757)
    	at java.lang.reflect.Method.invoke(Native Method)
    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
    Caused by: java.lang.SecurityException: Not allowed to delete channel foreground.service.channel with a foreground service
    	at android.os.Parcel.createExceptionOrNull(Parcel.java:3023)
    	at android.os.Parcel.createException(Parcel.java:3007)
    	at android.os.Parcel.readException(Parcel.java:2990)
    	at android.os.Parcel.readException(Parcel.java:2932)
    	at android.app.INotificationManager$Stub$Proxy.deleteNotificationChannel(INotificationManager.java:4757)
    	at android.app.NotificationManager.deleteNotificationChannel(NotificationManager.java:1034)
    	at com.davidbriglio.foreground.ForegroundService.startPluginForegroundService(ForegroundService.java:34)
    	at com.davidbriglio.foreground.ForegroundService.onStartCommand(ForegroundService.java:18)
    	at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5243)
    	at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0) 
    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2447) 
    	at android.os.Handler.dispatchMessage(Handler.java:106) 
    	at android.os.Looper.loopOnce(Looper.java:226) 
    	at android.os.Looper.loop(Looper.java:313) 
    	at android.app.ActivityThread.main(ActivityThread.java:8757) 
    	at java.lang.reflect.Method.invoke(Native Method) 
    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) 
    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) 
    Caused by: android.os.RemoteException: Remote stack trace:
    	at com.android.server.notification.NotificationManagerService$12.enforceDeletingChannelHasNoFgService(NotificationManagerService.java:4667)
    	at com.android.server.notification.NotificationManagerService$12.deleteNotificationChannel(NotificationManagerService.java:4680)
    	at android.app.INotificationManager$Stub.onTransact(INotificationManager.java:2172)
    	at android.os.Binder.execTransactInternal(Binder.java:1316)
    	at android.os.Binder.execTransact(Binder.java:1280)

To Reproduce
Steps to reproduce the behavior:

  1. My App is crashing when I click to play a chapter. HERE is my app's Github

Expected behavior
A foreground service started

Smartphone (please complete the following information):

  • Device: Samsung Galaxy Tab A7 Lite
  • OS: Android
  • Plugin Version:

Additional context
I managed to fix the problem by using a try/catch

ForegroundService.java:34

try{
    manager.deleteNotificationChannel("foreground.service.channel");
  } catch(Exception e) {
  // just ignore the exception for now. better than crashing my app
  e.printStackTrace();
}

Application crashes on Android 11 - java.lang.SecurityException

NOTE: Please make sure you read the readme and fully understand the use of this plugin and its requirements before opening an issue.

Describe the bug
Hi, I've been working on the main app where I work. One of its main features is the ability to take pictures.

As you will see in the environment below, I use ionic with angular, and what happens to me is the following:

On some devices, the ionic camera plugin has been resetting its state, due to the memory wipe that android does with apps in the background, since the ionic camera plugin opens the camera's native app, and only after back to your app.

After some research I fixed this using the foreground plugin for ionic (this plugin), opening it before the camera starts, and then closing it, to prevent android from understanding that my app is in the background and resetting it.

This fixed the problem for most devices, except for some devices that use android 11, strangely not all.

After taking a look at the google play crash logs, I noticed that most of them gave the error below, coming from this plugin.

image
image

To Reproduce
Well, it's not very clear how to reproduce this problem. What I do know is that it happens on android 11 due to security issues implemented in this version, as you can see here: https://developer.android.com/guide/components/foreground-services

See some implementation of mine:
image
image

Expected behavior
Should open the foreground service without crashing the app

Smartphone (please complete the following information):

About affected devices:
image

About the version of things:
image
image

  "dependencies": {
    "@angular/common": "^7.2.2",
    "@angular/core": "^7.2.2",
    "@angular/forms": "^7.2.2",
    "@angular/platform-browser": "^7.2.2",
    "@angular/platform-browser-dynamic": "^7.2.2",
    "@angular/router": "^7.2.2",
    "@ionic-native/android-permissions": "^5.35.0",
    "@ionic-native/app-rate": "^5.12.0",
    "@ionic-native/app-version": "^5.21.5",
    "@ionic-native/barcode-scanner": "^5.0.0",
    "@ionic-native/call-number": "^5.1.0",
    "@ionic-native/camera": "^5.34.0",
    "@ionic-native/core": "^5.0.0",
    "@ionic-native/crop": "^5.0.0",
    "@ionic-native/device": "^5.0.0",
    "@ionic-native/file": "^5.0.0",
    "@ionic-native/file-transfer": "^5.28.0",
    "@ionic-native/foreground-service": "^5.34.0",
    "@ionic-native/image-picker": "^5.0.0",
    "@ionic-native/in-app-browser": "^5.15.1",
    "@ionic-native/ionic-webview": "^5.0.0",
    "@ionic-native/launch-navigator": "^5.0.0",
    "@ionic-native/market": "^5.21.5",
    "@ionic-native/media-capture": "^5.28.0",
    "@ionic-native/network": "^5.5.1",
    "@ionic-native/push": "^5.5.0",
    "@ionic-native/screen-orientation": "^5.2.0",
    "@ionic-native/social-sharing": "^5.35.0",
    "@ionic-native/splash-screen": "^5.0.0",
    "@ionic-native/status-bar": "^5.0.0",
    "@ionic-native/video-editor": "^5.28.0",
    "@ionic/angular": "^4.2.0",
    "@ionic/pro": "2.0.4",
    "@ionic/storage": "^2.2.0",
    "@ngx-translate/core": "^11.0.1",
    "@sentry/browser": "5.1.1",
    "@types/crypto-js": "^4.0.2",
    "@types/moment-timezone": "^0.5.12",
    "ajv": "^6.10.0",
    "angular2-signaturepad": "https://github.com/FieldControl/angular2-signaturepad",
    "br-mask": "0.0.10",
    "call-number": "1.0.1",
    "chart.js": "2.9.3",
    "cordova-android": "9.1.0",
    "cordova-android-support-gradle-release": "^2.1.0",
    "cordova-ios": "5.1.0",
    "cordova-plugin-actionsheet": "^2.3.3",
    "cordova-plugin-app-version": "^0.1.9",
    "cordova-plugin-apprate": "1.4.0",
    "cordova-plugin-background-fetch": "~7.0.1",
    "cordova-plugin-cocoalumberjack": "0.0.4",
    "cordova-plugin-crop": "^0.4.0",
    "cordova-plugin-device": "2.0.2",
    "cordova-plugin-dialogs": "^2.0.1",
    "cordova-plugin-file": "^6.0.1",
    "cordova-plugin-file-transfer": "^1.7.1",
    "cordova-plugin-globalization": "1.11.0",
    "cordova-plugin-inappbrowser": "3.1.0",
    "cordova-plugin-ionic": "^5.3.0",
    "cordova-plugin-ionic-keyboard": "^2.1.3",
    "cordova-plugin-ionic-webview": "^2.4.1",
    "cordova-plugin-market": "^1.2.0",
    "cordova-plugin-media-capture": "^3.0.3",
    "cordova-plugin-nativestorage": "2.3.2",
    "cordova-plugin-network-information": "^2.0.1",
    "cordova-plugin-screen-orientation": "^3.0.1",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-telerik-imagepicker": "2.3.3",
    "cordova-plugin-whitelist": "^1.3.3",
    "cordova-sqlite-storage": "^3.2.0",
    "core-js": "^2.5.4",
    "crypto-js": "^4.1.1",
    "es6-promise-plugin": "^4.2.2",
    "ionic2-calendar": "^0.5.7",
    "leaflet": "^1.4.0",
    "lodash": "^4.17.11",
    "loki-cordova-fs-adapter": "^1.0.2",
    "lokijs": "^1.5.6",
    "moment-timezone": "^0.5.23",
    "phonegap-plugin-barcodescanner": "^8.0.1",
    "phonegap-plugin-multidex": "^1.0.0",
    "phonegap-plugin-push": "2.3.0",
    "rxjs": "^6.5.0",
    "semver": "^7.3.2",
    "uk.co.workingedge.phonegap.plugin.launchnavigator": "^5.0.4",
    "uuid": "^3.3.2",
    "zone.js": "~0.8.29"
  },
  "devDependencies": {
    "@angular-devkit/architect": "~0.12.3",
    "@angular-devkit/build-angular": "^0.13.8",
    "@angular-devkit/core": "~7.2.3",
    "@angular-devkit/schematics": "~7.2.3",
    "@angular/cli": "~7.2.3",
    "@angular/compiler": "~7.2.2",
    "@angular/compiler-cli": "^7.2.6",
    "@angular/language-service": "~7.2.2",
    "@ionic/angular-toolkit": "~1.2.0",
    "@types/chart.js": "^2.9.23",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/leaflet": "^1.4.2",
    "@types/lodash": "^4.14.120",
    "@types/lokijs": "^1.5.2",
    "@types/node": "~10.12.0",
    "@types/semver": "^7.3.4",
    "@types/uuid": "^3.4.4",
    "codelyzer": "~4.5.0",
    "cordova-background-geolocation": "git+https://github.com/transistorsoft/cordova-background-geolocation.git#4.0.1",
    "cordova-plugin-android-permissions": "^1.1.2",
    "cordova-plugin-androidx": "^3.0.0",
    "cordova-plugin-androidx-adapter": "^1.1.3",
    "cordova-plugin-camera": "^5.0.2",
    "cordova-plugin-foreground-service": "^1.1.3",
    "cordova-plugin-video-editor": "git+https://github.com/AlexMiniApps/cordova-plugin-video-editor.git",
    "cordova-plugin-x-socialsharing": "^6.0.3",
    "cordova-support-google-services": "^1.3.2",
    "fcm-node": "^1.4.0",
    "husky": "^4.2.5",
    "ionic": "5.4.16",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~8.0.0",
    "tslint": "~5.12.0",
    "typescript": "~3.1.6"
  }

Additional context

Well, i think the solution to this have some to do with this permissions:
image

So i tried:

<service android:foregroundServiceType="camera" android:name="com.davidbriglio.foreground.ForegroundService.startPluginForegroundService" />

But when i tried to do it i am getting this error:
image

And i am in a dead end :( What i doing wrong?

AAPT Error and SDK 30

SDK 30 is requiring android:foregroundServiceType in the manifest which is causing an AAPT error with Cordova 8.1.2

Cordova version

Hi, Is it possible to make this plugin compatible with cordova 7.1.0 and cordova-android 6.3.0?

Thanks.

foregroundService is not started

Hi, i am trying this plugin on VueJS. For some reason, the service is not started, i've put this line
cordova.plugins.foregroundService.start('GPS Running', 'Background Service', 'icon', 3, 10);

Nothing happened, not shown any notification, so i'm not sure if the service does really run.
But the cordova.plugins.foregroundService does exist when i debug it like the following.

image

I am using cordova 9.0.0
Would you mind telling me the issue?

Application crashes java.lang.NullPointerException

Dear All,

we are getting a lot of crash reports in the Play Console, stack trace:

java.lang.RuntimeException: at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:4319) at android.app.ActivityThread.access$2700 (ActivityThread.java:273) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2070) at android.os.Handler.dispatchMessage (Handler.java:112) at android.os.Looper.loop (Looper.java:216) at android.app.ActivityThread.main (ActivityThread.java:7625) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:524) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:987) Caused by: java.lang.NullPointerException: at com.davidbriglio.foreground.ForegroundService.onStartCommand (ForegroundService.java:16) at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:4298)

It looks like it happening mostly on Huawei devices

Any suggestion?

Screenshot 2021-09-28 at 10 23 55

Appication crashes on launch and giving foreground services error

NOTE: Please make sure you read the readme and fully understand the use of this plugin and its requirements before opening an issue.

Describe the bug
I was using foreground services for GPS tracking and it was working fine. But now i added camera plugin after on every app launch I am receiving this error I dont know what does it means

2021-07-05 06:52:56.407 4612-4612/com.siloc.users E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.siloc.users, PID: 4612
    java.lang.RuntimeException: Unable to start service com.davidbriglio.foreground.ForegroundService@7e19bfc with Intent { act=start cmp=com.siloc.users/com.davidbriglio.foreground.ForegroundService (has extras) }: java.lang.SecurityException: Not allowed to delete channel foreground.service.channel with a foreground service
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4432)
        at android.app.ActivityThread.access$2100(ActivityThread.java:259)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2142)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:230)
        at android.app.ActivityThread.main(ActivityThread.java:7880)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:526)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)
     Caused by: java.lang.SecurityException: Not allowed to delete channel foreground.service.channel with a foreground service
        at android.os.Parcel.createException(Parcel.java:2085)
        at android.os.Parcel.readException(Parcel.java:2053)
        at android.os.Parcel.readException(Parcel.java:2001)
        at android.app.INotificationManager$Stub$Proxy.deleteNotificationChannel(INotificationManager.java:3589)
        at android.app.NotificationManager.deleteNotificationChannel(NotificationManager.java:788)
        at com.davidbriglio.foreground.ForegroundService.startPluginForegroundService(ForegroundService.java:34)
        at com.davidbriglio.foreground.ForegroundService.onStartCommand(ForegroundService.java:18)
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4414)
        at android.app.ActivityThread.access$2100(ActivityThread.java:259) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2142) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:230) 
        at android.app.ActivityThread.main(ActivityThread.java:7880) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:526) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034) 
     Caused by: android.os.RemoteException: Remote stack trace:
        at com.android.server.notification.NotificationManagerService$10.enforceDeletingChannelHasNoFgService(NotificationManagerService.java:2938)
        at com.android.server.notification.NotificationManagerService$10.deleteNotificationChannel(NotificationManagerService.java:2953)
        at android.app.INotificationManager$Stub.onTransact(INotificationManager.java:1525)
        at android.os.Binder.execTransactInternal(Binder.java:1021)
        at android.os.Binder.execTransact(Binder.java:994)

To Reproduce
Steps to reproduce the behavior:

  1. use background location tracking and camera at the same time
  2. Ctry to launch the app

Expected behavior
It should crash the application .Application itself is working fine

Smartphone (please complete the following information):

  • Vivo 2029
  • OS: [e.g. iOS8.1]
  • Plugin Version: 5.34.0

Make timer to work in the background on app lock/sleep

NOTE: Please make sure you read the readme and fully understand the use of this plugin and its requirements before opening an issue.

Problem definition

App is an ionic4 capacitor app which uses few cordova plugins as well. I have a timer feature associated with a bluetooth device that has to keep running even when the phone goes to sleep or in locked mode. Using the cordova-background-mode plugin the app works in the background, but as soon as phone is locked or in sleep the timer stops working. When the screen resumes, the timer continues from where it stopped.

I cannot use the platform pause and resume events in my case as just taking the difference and adding up with the time will provide wrong values with my use case. The use case if explained below:

This app is used with the height adjusting table connected via bluetooth, where a user can use the app to adjust the height and also track the time when he is in standing position. (The timer starts running when the table reaches a certain height - achieved using the startNotification method of ble). The height adjusting table also has button to control its height.

Use case (Why I cannot use the platform resume and pause events along with timestamps) :

  1. Desk is in standing position. Timer starts running.
  2. I lock my phone (timestamp created - on pause event trigger)
  3. I go in sitting position for 1h (The table also has buttons to control the height, so this is referred to when the user uses that to reduce the height and is in sitting position, but the phone is still locked/sleep and is not notified about the change)
  4. I go back to standing position for 20min
  5. I unlock my phone. (Second time stamp created - on resume event trigger)
  6. Now it will show 1hour 20min standing time even though I stood only 20min

How can I make wake the phone or notify when the ble device state changes even when the phone is locked? I tried by including the script inside the startNotification method which would create a timestamp in the DB when the height is adjusted. But this doesn't work if the phone is locked/sleep.
That's when I tried to use the foreground plugin along with the background mode, but it did not result in a DB service on changes of the state of the device.

Expected behavior
The timer should either run in the background like the music player app which continues to play even on phone lock. Or it should be able to create a DB call on state change of the device. Any of the above approaches would be fine, but the correct time has to be tracked.

Android 8 and higher

If I understood correctly this plugin is only for users who have Android 8 and higher??

android-sdk version check failed

I get this message when I add the plugin.

Phonegap-Version 8.2.2
Phonegap-Android 7.1.2

<preference name="android-minSdkVersion" value="19" />
<preference name="android-targetSdkVersion" value="27" />

what else do I need?
It installs anyways, but cordova.plugins.foregroundService is undefined.

how to use in Ionic 3 app

Hello,

This is not an issue related to the plugin, but I am having a trouble to use this plugin in ionic 3 app.
Could anybody share an example how to use this plugin in ionic 3 app, please?

Thanks

Android 8.1 crash

When using in Android 8.1 sometimes (not always) the app has crashed with following errors.

08-16 21:15:47.541 2107 2108 E ANDR-PERF-RESOURCEQS: Failed to apply optimization [2, 0]
08-16 21:15:47.641 1115 1281 I ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.google.android.apps.nexuslauncher/.NexusLauncherActivity (has extras)} from uid 1000
08-16 21:15:47.641 756 756 D QCOM PowerHAL: LAUNCH HINT: ON
08-16 21:15:47.643 756 756 D QCOM PowerHAL: Activity launch hint handled
08-16 21:15:47.672 1115 1649 W ActivityManager: Bringing down service while still waiting for start foreground: ServiceRecord{3947e4b u0 com.+++.+++/com.davidbriglio.foreground.ForegroundService}
08-16 21:15:47.676 11001 11001 E AndroidRuntime: FATAL EXCEPTION: main
08-16 21:15:47.676 11001 11001 E AndroidRuntime: Process: com.+++.+++, PID: 11001
08-16 21:15:47.676 11001 11001 E AndroidRuntime: android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground()
08-16 21:15:47.676 11001 11001 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1768)
08-16 21:15:47.676 11001 11001 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
08-16 21:15:47.676 11001 11001 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164)
08-16 21:15:47.676 11001 11001 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6494)
08-16 21:15:47.676 11001 11001 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
08-16 21:15:47.676 11001 11001 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
08-16 21:15:47.676 11001 11001 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

The foreground service has been started when app is sent to background.

this.platform.pause.subscribe(() => { if (this.isPlaying) { this.foregroundService.start("title","description","ic_small_icon"); } else { this.foregroundService.stop(); } });

Android SDK 28 now requires FOREGROUND_SERVICE permission

An app with this plugin will crash due to lack of FOREGROUND_SERVICE permission if built against Android SDK 28 (which is now required in the app store).
The plugin should add a request for this permission to the Android manifest.

You can currently work around this issue by using this plugin - https://github.com/dpa99c/cordova-custom-config and adding the following into your config.xml under <platform name="android">:

<custom-preference name="android-manifest/uses-permission/@android:name" value="android.permission.FOREGROUND_SERVICE" />

How to use with capacitor-community/bluetooth-le

I need to upload firmware to a satellite antenna via Bluetooth LE. For that I'm using https://github.com/capacitor-community/bluetooth-le. The upload takes close to an hour. Obviously, I need to make sure that the upload continues if the app is moved to background or screen is turned off.

I'm struggling to understand the relation between this plugin and the needed background service. Is the bluetooth LE plugin a background service in itself, or would I need an additional service? Can you please give an example in pseudo code to guide me in the right direction? I would be happy to pay for a good example.

Notification icon not showing in Android 11

Not sure this plugin is still maintained, anyway here we go:

Describe the bug
The notification icon does not show in Android 11, the default star icon is shown instead

cordova.plugins.foregroundService.start('Epicollect5', 'Taking Photo...', 'ic_launcher.png', 2, 10);

Android 10

Android 11

Can you please change the minimum platform to 5.0.0

i.e. in plugin.xml instead of
engine name="cordova-android" version=">=7.0.0"
change to
engine name="cordova-android" version=">=5.0.0"
Although cordova-android older than 6.3 defaults to android-23, 24 or 25 and this plugin needs 26, it's possible to use older cordova-android platform (at least as old as 5.x) and manually specify which SDK level you want to compile against with target=android-26 in project.properties.
We've tested this plugin and it works just fine with cordova-android 5.2.2.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.