SayWut / flutter_foreground_service_plugin

MIT License
12 stars 12 forks source link

Feature: Start service when device boots #2

Closed toonvanstrijp closed 3 years ago

toonvanstrijp commented 3 years ago

Is it possible to start the foreground service when the devices boots?

SayWut commented 3 years ago

Nice idea I will add this option in the next update

toonvanstrijp commented 3 years ago

I have more idea's, will create a issue for it ;)

SayWut commented 3 years ago

I have more idea's, will create a issue for it ;)

shoot them at me ;)

SayWut commented 3 years ago

I published new update with this option

you can new set isStartOnBoot

toonvanstrijp commented 3 years ago

@SayWut just to confirm. Does this also start the "task" automatically at boot?

SayWut commented 3 years ago

@SayWut just to confirm. Does this also start the "task" automatically at boot?

yes if you see any bug open a new issue :)

toonvanstrijp commented 3 years ago

@SayWut how does it handle when the phone is in "doze" mode? (Haven't tested it yet tho)

But maybe we need an option for this:

https://developer.android.com/reference/android/Manifest.permission.html#REQUEST_IGNORE_BATTERY_OPTIMIZATIONS

SayWut commented 3 years ago

@SayWut how does it handle when the phone is in "doze" mode? (Haven't tested it yet tho)

But maybe we need an option for this:

https://developer.android.com/reference/android/Manifest.permission.html#REQUEST_IGNORE_BATTERY_OPTIMIZATIONS

Here comes the receiver that I created. If the OS kills the service the service will auto restart itself

you can see the onDestroy function in the service which handles this problem

https://github.com/SayWut/flutter_foreground_service_plugin/blob/b91463d4eb60835fea858a773c34c0b50a2fd665/android/src/main/java/com/saywut/flutter_foreground_service_plugin/FlutterForegroundService.java#L290

toonvanstrijp commented 3 years ago

@SayWut I'm testing it right now. What I notice is that when I'm using the perodic task with a duration of 15 minutes. It doesn't always run evry 15 minutes. Especially when the phone is locked. I thought maybe we can solve this by using the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS?

SayWut commented 3 years ago

@SayWut I'm testing it right now. What I notice is that when I'm using the perodic task with a duration of 15 minutes. It doesn't always run evry 15 minutes. Especially when the phone is locked. I thought maybe we can solve this by using the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS?

I don't see this request should be in my plugin because it opens a dialog which request from the user to remove the current app from the battery optimize manually

I will test it and I will check if there is somthing that I can do with this 15 minutes duration

SayWut commented 3 years ago

@SayWut I'm testing it right now. What I notice is that when I'm using the perodic task with a duration of 15 minutes. It doesn't always run evry 15 minutes. Especially when the phone is locked. I thought maybe we can solve this by using the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS?

I think I found a bug open a new issue about this and post there your periodicTaskFun