How to create a foreground service in NativeScript - android

A background service might not be working in real-time if the App turned background when Android SDK > 26 (Android OS 8.0 later), but a foreground service may work according to Ref1 & Ref2(Codes in Native Java), I'm no idea how translate it in NativeScript, could somebody make it? thanks!
Ref1: https://hackernoon.com/android-location-tracking-with-a-service-80940218f561
Ref2: https://bitbucket.org/tiitha/backgroundserviceexample/branches/

A foreground service example in NativeScript could be found here and downloaded for reference.

Related

How to restart flutter app when it's killed by the OS or User?

I have a Flutter app that I'm running a background service on and it works fine even if the user swipes it away. I see that there're a lot of guides targeting native android implementations of this issue but none for Flutter. I'm using flutter_background_service and it works just fine when the app is in the background but not when it is killed. The app needs to be running all the time to listen to accelerometer events and I've tried a lot of packages like workmanager and flutter_foreground_task but they don't work as I'd like. Workmanager can only run every 15 min but that's too long of a duration and foreground_task although it claims it prevents the app from closing, it doesn't actually do that.
I have no Kotlin experience so using Method channels is not viable at the moment for me,I can copy-paste code though :) and I know some Java. Are there any packages that I'm not aware of that can help me to always listen in the background for events and launch or bring the app to the foreground when I want it to?
Using the embedder, Flutter code can be integrated into an existing application as a module, or the code may be the entire content of the application. [Flutter architectural overview]
In other words, your Flutter app running on Android is a regular Android app which has the same constraints like any other Android app.
And as mentionend in the README file of workmanager:
Android will automatically change your frequency to 15 min if you have configured a lower frequency.
This statement can also be be found in the Android documentation:
Note: The minimum repeat interval that can be defined is 15 minutes (same as the JobScheduler API.
So, I'd say that you should respect that constraint for your Android app and not try to come up with a hack which works around it.

Foreground service example in Flutter

I am new to Flutter. Can anyone post the link or code for "android foreground service example with a notification"? I googled but didn't get any good example of foreground service.
I'm working on a project that includes an SMS package. This App has to be active on the foreground.
Update:
I have created my own implementation of android foreground service for Flutter called android_long_task. check it out it solved my problem. let me know if it solves your problem by raising an issue.I created my own library because the tutorial I mentioned just shows how to create a foreground service in java and that's all and as you have found out by now the other foregorund_service plugins have some problems.
Old answer (didn't help me):
if you're having a problem with this and none of the libraries mentioned in other answers worked for you. you might wanna give this tutorial from RetroPortal Studio a try. it's a total of 26 minutes which teaches you how to write a working foreground service for flutter android
I tried flutter_foreground_service but it has a big problem. When app closes this plugin throwing error. This bug is reported in here: https://github.com/pauldemarco/foreground_service/issues/1
foreground_service has problem too: https://github.com/pauldemarco/foreground_service/issues/1
Probably there isn't a good solution for now (Jan 2020). If someone develops a good solution may be I add it to here.
I think Google should find solution for this kind of problems. We're using flutter becouse we're thinking that flutter is more effective. If we lost our time kind of this absurd errors why we using flutter? Using kotlin for android, swift for ios this is more good probably.
Pauldemarco has created some excellent flutter packages for flutter. He has developed one for Foreground service too. As of now, it is only supported in android. It is not supported for iOS. I hope this helps.
https://github.com/pauldemarco/foreground_service
You can use library flutter_foreground_task for long or always running task.

React-Native Android - Api to find if the app is in foreground or background

Is it possible to find if the app is in foreground or background in React-Native Android platform? please point me to some reference code.
Thanks !
ActivityManager-->getRunningAppProcesses--> check every one if your app belongs it

How to use Android L UsageStatsManager?

I'm trying to get the application usage list in android lollipop using UsageStatsManager, for that I have gone through the android developer document https://developer.android.com/reference/android/app/usage/UsageStatsManager.html
I don't know how to use UsageStasManger, so I referred few links How to get list of recent apps with Android API 21 Lollipop?
Android Lollipop know if app as Usage Stats access
and implement in my project but I didn't get any data from UsageStausManager? how do I Use UsageStausManager in my project. Anyone help me out.
From lollipop we will not be able to use the activity manager for determining the current foreground tasks. we have to make use of the Usage Stats Manager. Wrote a small code and answered in this thread
Determining the current foreground application from a background task or service
You can have a look at this thread by me.

Roximity beacons Android SDK

I'm trying to create an app to work with ROximity beacons. I've tried to use Roximity 1.2 SDK, but had no success launching the app with it and because time is short - I was forced to use a demo project with 0.2 SDK, which was workin +/- ok.
Problem is - I cannot find any method in SDK to stop scanning for beacons and update interface, so when I close the app - scanning thread is still scanning (it is started somewhere in SDK automagically) and instead of proper closing it crashes.
Unfortunately, Roximity support isn't supporting much and they cannot provide any documentation, because there's not to much of it anyway and what is there - it is very very minimal: http://roximity.github.io/ROXDOX/roxandroid_s_d_k.html
The Roximity SDK is a modified version of an older version of the open source Android Beacon Library. You can review the documentation for the open source library at the link provided to see if helps with any questions. Obviously, Roximity's modifications may change the way things work. Worst case, you can simply switch to using the open source library.
With the open source library, you can stop scanning two ways:
Unbind all BeaconConsumer instances from the BeaconManager. (Preferred)
beaconManager.unbind(this);
Set the background between scan period to be very large and put the BeaconManager into background mode.
beaconManager.setBackgroundBetweenScanPeriod(Long.MAX_VALUE);
beaconManager.setBackgroundMode(true);
Full disclosure: I am the author of the open source library.

Categories

Resources