I am developing an app which uses an embedded system connected to through Bluetooth to an embedded device and I want the app to run a function when the device sends a signal.
The issue is that I cannot keep the app open all the time and thus need the app to keep running in the background and keep listening for the signal send by the embedded device so that it can run the function I want.
I have seen the following questions :
How to run flutter app in background continually?
How can I make my flutter app run in background without stopping?
How to create a service in Flutter to make an app to run always in background?
and many more and so far nothing seems to work.
I have written this code for now :
Future<void> _run_app_in_background() async {
final config = FlutterBackgroundAndroidConfig(
notificationTitle: 'MEDICA',
notificationText:
'MEDICA is running in the background',
notificationIcon: AndroidResource(name: 'background_icon'),
notificationImportance: AndroidNotificationImportance.Default,
);
var hasPermissions = await FlutterBackground.hasPermissions;
hasPermissions = await FlutterBackground.initialize(androidConfig: config);
final backgroundExecution =
await FlutterBackground.enableBackgroundExecution();
}
but it seems to be doing nothing and the same with other packages.
So how can I make my app run in background to keep listening for the Bluetooth data sent by device.
Edit:I want this to run on both Android and iOS and if possible maybe someone can suggest me another framework apart from Flutter (in comments maybe) and I can search the internet for the same.
#HrishabhNayal Hello bro Try this way!
https://medium.com/dlt-labs-publication/flutter-run-code-in-the-background-461b4d6c635b
Related
I've recently been trying to get a mobile app I'm working on functioning in react-native android. For context I have a few services that I start that are served on :5009 and :5010 respectively, these services are used for basically offline API calls that I store on the phone itself and run with a golang web server cross compiled from gomobile. The services start by just running a function that just initializes the server.
The issue is, I've gotten these services to work on both android with a non-react-native java version using a foreground intent service and in iOS using DispatchQueue background pretty easily actually.
I've tried using a headless js service (foregroundBool on and off) that calls java code, starting a foreground service in the main application itself and a bunch of other stuff but nothing seems to be working as desired. I'm kind of out of ideas and basically running into variations of the same problem (if one starts the other one blocks) so any suggestion would be greatly appreciated.
It looks like a true foreground service in android might not be possible with react-native after doing a bit more research? Is this accurate?
Thanks,
I have an integration test which taps a text of phone number, then it opens the phone dial app which makes my app put to background.
final firstNumber = find.byWidgetPredicate(
(widget) => widget is RichText && tapTextSpan(widget, '09123456789'));
await tester.tap(firstNumber);
After tester.tap() it successfully open the built in dial app in phone.
How can I bring my app to foreground?
Package used: integration_test, flutter_test
You can use flutter_foreground_task package
use FlutterForegroundTask.minimizeApp() for app to background
and FlutterForegroundTask.launchApp() for app to foreground
that's all. I hope it helps.
I am trying to create an App that will respond with locations of people in a group when anyone requests it - similar to what Find My Friends (FMF) does but across Android and iOS and I am using Phonegap. I have been researching how the FMF App returns locations - along the lines of this SO Post and am trying to understand that better.
At some point iOS will terminate the App due to memory pressure. I understand if you set your Background mode in Capabilities section of XCode to location and if there is a significant change in location the App will restart in Background. Is that what the FMF App is doing to ensure it stays up to respond to location request?
When location is requested I send a push notification (data notification only so it is processed in the background - users doesn't see it) and the App is expected to respond if it is in Background/Foreground. However in the case of iOS if the App has been terminated by iOS and there has been no significant location change, the App will not be up and running in Background and won't respond. Is that the best we can do besides somehow preventing iOS from suspending/terminating the App? Appreciate any insights.
I have read about creating background services to help but that seems to apply more to Android than to iOS.
Thank you for any guidance and pointers.
Sanjay.
First of all, you shoud Declaring Your App’s Supported Background Tasks.
Support for some types of background execution must be declared in advance by the app that uses them. In Xcode 5 and later, you declare the background modes your app supports from the Capabilities tab of your project settings. Enabling the Background Modes option adds the UIBackgroundModes key to your app’s Info.plist file. Selecting one or more checkboxes adds the corresponding background mode values to that key.
Then Tracking the User’s Location and cached the latest location.
And handle your remote notification to upload the latest location.
When your want to get somebody's location, Server push a remote-notification to the Client with APNS, and Client handle the remote-notification with application:didReceiveRemoteNotification:fetchCompletionHandler:
Or timed to upload location with Finite-Length Tasks in the background:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
bgTask = [application beginBackgroundTaskWithName:#"MyTask" expirationHandler:^{
// Clean up any unfinished task business by marking where you
// stopped or ending the task outright.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task, preferably in chunks.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}
Hope that help you ~
I like to know how to exit an app in a good way in Android and Ios?
In the helloworld app of cocos2d-js this code is unfortunately omitted:
var closeItem = cc.MenuItemImage.create(
res.CloseNormal_png,
res.CloseSelected_png,
function () {
cc.log("Menu is clicked!");
}, this);
What can be there instead of
cc.log("Menu is clicked!");
?
For Android, you should call CCDirector::sharedDirector()->end(); to end the app. For Apple though, you could call exit(0) but its not really recommended to exit apps and will appear sort of like a crash. Do you need a close button? Most apps don't tend to have them and just keep running until the system or the user kills them.
I am writing a simple Phonegap application for Android. This program will send notification to notification bar and make the phone vibrate periodically.
I use navigator.notification.vibrate(time_period) to achieve the target. According to this article, both beep and vibration are not supported by android emulator. Hence, I was expecting that there could be entry indicating failure of it in the Catlog, but there is no such entry. The question is how to make sure that a vibration event has happened or failed (without deploying to a device).
AppHarbor looks like one of the ways to debug Phonegap application remotely. I wonder if there is other local ways to test Phonegap application as an HTML5 website in a Chrome browser (navigator.notification call is a standard call)? If yes, then it is probably possible to somehow parse the browser's console automatically to find out if the vibration event has happened.
Can you hide the vibrate() call behind an abstraction which you can replace depending on which platform you are using?
For example
var vibrateFunc = function(time_period) {
if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
console.log('vibrating for ' + time_period)
} else {
navigator.notification.vibrate(time_period)
}
}
and then have your app code call vibrateFunc() whenever it wants to vibrate.