flutter_background_service
flutter_background_service copied to clipboard
Background other libraries
I want to check the latest sms by timer. I can do this manually or through a listener. Tried different libraries, with any error. As far as I understand, there is no such possibility?
Small sample:
void onStart() async {
WidgetsFlutterBinding.ensureInitialized();
final service = FlutterBackgroundService();
Timer.periodic(Duration(seconds: 5), (timer) async {
SmsReceiver receiver = new SmsReceiver();
receiver.onSmsReceived.listen((msg) => print(msg.body));
});
Error:
Error handling 'checkPlatformOverride' custom request: method not available: ext.flutter.platformOverride
Error handling 'checkBrightnessOverride' custom request: method not available: ext.flutter.brightnessOverride
Error handling 'checkPlatformOverride' custom request: method not available: ext.flutter.platformOverride
Error handling 'checkBrightnessOverride' custom request: method not available: ext.flutter.brightnessOverride
2
Error handling 'checkIsWidgetCreationTracked' custom request: method not available: ext.flutter.inspector.isWidgetCreationTracked
E/EventChannel#plugins.babariviere.com/recvSMS(10573): Failed to open event stream
E/EventChannel#plugins.babariviere.com/recvSMS(10573): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.app.Activity.checkSelfPermission(java.lang.String)' on a null object reference
Hi @VisualMafia, background service don't provide Ui, you have to check permission from the Ui before start the service.
Yes, I did that too, in the beginning I created SmsReceiver receiver = new SmsReceiver ();, I asked for native permissions and then turned on the service. But, interestingly, vibro works without problems on a timer, audio too, device_info. And all libraries with reading calls or SMS do not work. Maybe there will be more ideas on how you can read SMS or calls in the background?
@VisualMafia I think, the plugin depends on an Activity (android native class), but background service is not an Activity, so we can’t execute anything depends on Activity in background service since background service is able to run without Activity.
Yes, it probably is. Although, it is very strange why such libraries have Activity, they do not have a UI. Don't you know if it is possible to run an application from a service if the application has been completely unloaded? Check the status by timer, if the OS is unloaded or the user, then start again.
@VisualMafia because they need Activity for check and request permission.
As far as I understand, even if I give all permissions in advance, all the same these libraries will use Activity and this cannot be solved?
@VisualMafia yes, because the plugin source code need Activity's context to perform permission checks.
as we can see, the plugin execute android.app.Activity.checkSelfPermission(java.lang.String)
.
What would you do in this situation? :)
@VisualMafia looking another plugin that doesn't require Activity
Searched, could not find, probably because of permissions. Don't you know if you can run the application from the service if it has been unloaded?
I will probably set a alarm to start app and check the state of the application through SystemChannels.lifecycle. Thanks for your answers and help!