Can Flutter application function in the background? - flutter

I am new to flutter.
I want to build a map application that shows collectable items on a map. When the users are near the item they can collect them. I have to make call to server to indicate that user collect the item.
I understand the application will function when it is in the foreground. But if the application is in the background can it perform these functions? For example: update users location, get items based on the location, collect items etc.
Does flutter can perform these functions normally if it is in the background or we have to create say some service type of application to do this?
I appreciate any advice regarding this.

Yes, you can do it, but you will need to create this methods with kotlin / java and use the platform channels to invoke it.

Yes you can workmanger is for running something on the background in your flutter app and it supports dart directly Workmanager. Alternatively native code will work for you swift or objective-c for ios and kotlin or java for android depending on which default native languages you tell flutter to create project with but that becomes very complex especially over ios side if you have no prior experience. Try your best with workmanager see if that can work.
Put a look to firebase schedule functions and cron as well see if they can do the job as well for you
Firebase Schedule Functions
Cron Flutter

Related

Compare two pictures with each other with Ionic

Is it possible to compare two images with Ionic?
The scenario would be this: I have a database with 50 different images of different flowers and corresponding metadata like title and description. If I now take a picture of a flower with my smartphone, can I assign this picture to another one to find the most suitable result?
Do I need services like the Google Cloud Vision API to do this? Or can I do it internally because I already have the database?
PS: If a server is required, Cloud Functions would be a possibility. For example, programming in Python would be possible there.
No Ionic cannot do this.
Ionic is just a UI framework that allows you to build cross-platform apps and specifically mobile apps (iOS, Android, [formerly] WindowsMobile).
What you're trying to do is something that another system could do. Check out OpenCV,
which would be more suitable for your purposes, and then you can use Ionic to build a nice interface around it.

Using Isolates in Flutter

I am trying to understand how I can create a background process in a Flutter Application. Basically, My understanding is that once a user has started the application, the Isolate can be created. This will allow my code to run on the background.
In the background, I want to get a list of Bluetooth enabled devices and their RSSI values within a certain radius, every 30 seconds or so.
I am aware that there are some Bluetooth libraries available for Flutter, but Time is really limited and It would be best to seek advice from experienced flutter developers.
Specifically, I would like to know the following -
Is using Isolates the best way to go about doing this? From my research, I understand that the user has to start the Isolate through some UI Activity?
Could the Isolate(Background Service) repeat every periodically to perform certain tasks?
I need to be able to write the data received from the Bluetooth scan to a database. I understand that the Isolate will not be the best place for this? Based on this blog post by Ben Konyi, it is not good practice to do such tasks within an Isolate.

It's possible run code like a "background service" when the app is closed using flutter?

I need to run a dart code for each 30s even if the application is closed. Is it possible?
Some workarounds suguested is use AlarmManager for Android, but, I not found solution for iOS.
There's no good article on how to implement an isolate to work when the app is closed without running some native code. In total, I have spent 2 full days trying to find a package for this, but nothing exists that works. Flutter_Isolate doesn't run when app is killed and Flutter Workmanager can only do print statements but can't take in any functions or any method call. Ultimately pathetic and very annoying. The only solution seems is to write native code to handle background tasks when app is closed. Shame on flutter.
Yes, it is possible. You can run Flutter in background.
In Flutter, you can execute Dart code in the background.
The mechanism for this feature involves setting up an isolate.
Isolates are Dart’s model for multithreading, though an isolate
differs from a conventional thread in that it doesn’t share memory
with the main program. You’ll set up your isolate for background
execution using callbacks and a callback dispatcher.
Source: Background processes
Yes its possible you can run a flutter app in background even if the app is closed using the following package:
https://pub.dev/packages/flutter_background_service
try using these two packages
https://pub.dev/packages/workmanager
https://pub.dev/packages/flutter_background_service

Listening to incoming notifications Flutter

I am deciding whether to use Flutter for cross platform app. I have investigated in ways to implement other functionalities.
But I need one other feature to implement which needs listening to incoming notification from other app in background. (something like notification listener in Android)
While I was searching came across the issue here which may effect what I intend to implement.
Is there any way to achieve what I want in Flutter?
I am willing to write plugins in native languages if its possible.
You can benefit from platform channels to write a plugin to utilise native code for each platforms. This medium post explains how to execute dart in the background and have example code for Android (Kotlin) and iOS (Objective-C).
However, according to this SO post you are not able to create an similar service like a NotificationListener for iOS.

Is it possible to activate ionic app on call

I am not sure it is possible in ionic or not. What i want to do is create an app that can record user calls. so app must be activate when user make or get a call.
can anyone tell me if it is possible, how to do this?
Beware this won't be an easy task but "never give up, never surrender". You'll want to use a variation of techniques first off this isn't an Ionic thing as much as it is a PhoneGap thing - ionic runs on phonegap.
Your workflow will look something like this:
User opens your app sees a list of contacts
(the formatted names of contacts are different for android & ios so be prepared to test for this.
http://ngcordova.com/docs/plugins/contacts/)
Contacts are displayed in ion-list user select one and phone's dialer launches (use href=tel:xxxxx)
From there you're going to want to trigger the audio capture plugin's API
https://github.com/apache/cordova-plugin-media-capture
To add the plugin to your project:
cordova plugin add cordova-plugin-media-capture
While it doesn't directly say it can record in call conversations it should still work.
It can definitely be done the storage space is also of concern, you'll have to set something in place to tell the user how many seconds/minutes they have the capacity to store.
That should get you started there will certainly be unforeseen nuances.
Good luck.
We can record calls with cordova-media-plugin plugin in android.
First install the media Plugin by executing the following command
cordova plugin add cordova-plugin-media
Then goto the Plugin folder and traverse into the following file “plugins\cordova-plugin-media\src\android\AudioPlayer.java” . Here in the startRecording function we have line
this.recorder.setAudioSource(MediaRecorder.AudioSource.MIC); line number is 154
Change it to this.recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
We can replace MIC with any audio source in the following link. for example VOICE_COMMUNICATION,VOICE_DOWNLINK,VOICE_RECOGNITION etc
https://developer.android.com/reference/android/media/MediaRecorder.AudioSource.html