Comments (19)
i don't know how your code exactly will make the app works even when the main is closed but if you try to run the example you will find that It works fine on the background thread else you can use one of the background tasks plugins such like foreground_task flutter
from flutter_overlay_window.
I have a basic broadcast receiver, which is triggered on any incmoing call. Based on whether my app is in foreground or background(closed), it invokes
flutter callbacks. This is also done in the Telephony
plugin for SMS. This part is working. In my background callback I am simply calling FlutterOverlayWindow.showOverlay
. Here I am getting the above error
void onNewCallBg(String msg) {
//background callback
debugPrint("new incoming call : $msg");
await FlutterOverlayWindow.showOverlay(
height: 500,
enableDrag: true,
overlayMessage: "TEST",
alignment: OverlayAlignment.center,
);
FlutterOverlayWindow.shareData(jsonEncode(msg));
}
In your example app, I close the app AFTER I show the opverlay. Here my requirement is different. The app is already closed and I am trying to show the overlay.
from flutter_overlay_window.
Here is a sample app using Telephony
plugin
main.dart
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_overlay_window/flutter_overlay_window.dart';
import 'package:flutter_overlay_window_example/overlays/true_caller_overlay.dart';
import 'package:telephony/telephony.dart';
void main() {
runApp(const MyApp());
}
@pragma("vm:entry-point")
void overlayMain() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MaterialApp(
debugShowCheckedModeBanner: false,
home: TrueCallerOverlay(),
));
}
void doPost(String msg) async {
await FlutterOverlayWindow.showOverlay(
height: 500,
enableDrag: true,
alignment: OverlayAlignment.center,
);
FlutterOverlayWindow.shareData(jsonEncode(msg));
}
void onNewSmsBg(SmsMessage msg) {
debugPrint("[CALL_HANDLER] on new sms bg ${msg.body}");
doPost(msg.body ?? "");
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
final _smsHandlerPlugin = Telephony.instance;
@override
void initState() {
super.initState();
initPlatformState();
initSmsHandler();
}
Future<void> initSmsHandler() async {
var smsPerm = await _smsHandlerPlugin.requestPhoneAndSmsPermissions;
await FlutterOverlayWindow.requestPermission();
_smsHandlerPlugin.listenIncomingSms(
onNewMessage: (msg) {
debugPrint("on new sms fg ${msg.body}");
},
onBackgroundMessage: onNewSmsBg);
}
}
I have added Telephony
as dependency in pubspec.yaml
and added an entry for the OverlayService
in my manifest file. Here the same issue. When the app is in foreground onNewMessage
is called. When the app is minimized, onNewSmsBg
is called and the overlay window is shown. But when I close my sample app, onNewSmsBg
is called but I get the above exception and no overlay window is shown. I get the first error mentioned (no service while in background) if I don't modify the code as mentioned above. After the change, I get the second error.
Hope I have been able to show the issue. Thanks
from flutter_overlay_window.
i don't know if I get it but for me when I used the overlay package I used foreground_task flutter
so even if I closed the app activity the overlay will not be killed cuz I have a running background task
clone this project and run it to check
foreground_app_test
from flutter_overlay_window.
Thanks for the reply. I will check it. The above link is not working
from flutter_overlay_window.
The above link is not working
https://github.com/X-SLAYER/foreground_app_test
from flutter_overlay_window.
The above link is not working
Are you refereing to https://github.com/X-SLAYER/foreground_plugins_test ? Because the above link is not working
from flutter_overlay_window.
The problem is that FlutterEngineCache
does not hold a reference to a flutter engine with id OverlayConstants.CACHED_TAG
once the app is closed.
from flutter_overlay_window.
i really don't know i will try to check it and get back to you
from flutter_overlay_window.
it's working fine for me just try this project I run the app background task then I closed the main activity after seconds the overlay has been launched from the background check it here
https://github.com/X-SLAYER/foreground_app_test/blob/main/lib/pages/first_task_handler.dart
from flutter_overlay_window.
I have figured out how to run the overlay in background, without using oreground_task flutter
. As mentioned previously FlutterEngineCache
does not hold a reference to a flutter engine with id OverlayConstants.CACHED_TAG
once the app is closed. So in onCreate
I am checking if cache already has a reference to the engine and if not create a new one. That seems to solve the problem. But now I have started a foreground service (the first error).
The link you have provided is not working. May be some network issue
.
from flutter_overlay_window.
i really don't know i will try to check it and get back to you
Sure. You can use my sample code to see the issue. The sample code uses Telephony plugin. When you close the app and a new SMS is received, it will raise the error.
from flutter_overlay_window.
mb repository was private now it's public
from flutter_overlay_window.
Thank you very much
from flutter_overlay_window.
Okay, I think the problem still persists. In your code you have started the foreground service and then you have closed tha app. In my case the app is already closed and I am trying to create the service. Again the cache does not hold a reference to the engine.
Please look into the sample I have provided. In the sample even if I start a foreground task, it's not working.
from flutter_overlay_window.
i don't have any idea about it it's not logic to start an activity while the app is closed even the engine will be killed so I think it's not posible
from flutter_overlay_window.
Consider the truecaller app. The app is not actively running all the time. Yet when a call arrives, it shows an overlay with the caller information. This might be a possible use case. Anyway, I am closing it.
from flutter_overlay_window.
Consider the truecaller app. The app is not actively running all the time. Yet when a call arrives, it shows an overlay with the caller information. This might be a possible use case. Anyway, I am closing it.
the truecaller app has a background service that works it's the same you can use workmanager or flutter_foreground_task plugins
from flutter_overlay_window.
I have the same or a similar issue.
the window overlay CAN be started from a background thread ( i use the plugin flutter_background_service) but only when the main activity was called before with the entrypoint
@pragma("vm:entry-point")
void overlayMain() {
but when the main activity got deleted by the system and the background service starts the window overlay i get the following error message:
Fatal Exception: java.lang.RuntimeException: Unable to create service flutter.overlay.window.flutter_overlay_window.OverlayService: java.lang.NullPointerException: Attempt to invoke virtual method 'io.flutter.embedding.engine.dart.DartExecutor io.flutter.embedding.engine.FlutterEngine.getDartExecutor()' on a null object reference
This can be reproduced by adding flutter_background_service to a window overlay project and activate "start on boot". then restart the device and the app crashes
Here the full error stacktrace:
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'io.flutter.embedding.engine.dart.DartExecutor io.flutter.embedding.engine.FlutterEngine.getDartExecutor()' on a null object reference
at flutter.overlay.window.flutter_overlay_window.OverlayService.<init>(OverlayService.java:37)
at java.lang.Class.newInstance(Class.java)
at android.app.AppComponentFactory.instantiateService(AppComponentFactory.java:129)
at androidx.core.app.CoreComponentFactory.instantiateService(CoreComponentFactory.java:75)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4370)
at android.app.ActivityThread.access$1900(ActivityThread.java:274)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2112)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:233)
at android.app.ActivityThread.main(ActivityThread.java:8010)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
from flutter_overlay_window.
Related Issues (20)
- Invalid file path for libcolorx-loader.so Error while rendering model viewer widget inside overlay.
- Error on demo code
- Overlay window doesn't work in apk release mode
- Android API 33 crashes HOT 3
- Values in resizeOverlay not coherent with values in showOverlay HOT 2
- Crached when close overlay in android 12 HOT 5
- Wrong size when switching between portrait and landscape mode.
- Can flutter_web be used in Windows?
- TextFormField not supported HOT 1
- Not able to add any other plugin into the overlay screen
- Not able to receive message from flutter_background_service HOT 1
- when call Function showOverlay() nothing action HOT 2
- add ios support HOT 5
- Unable to create service flutter.overlay.window.flutter_overlay_window.OverlayService: HOT 4
- Add support for android API 34 HOT 1
- Height doesn't account for status bar
- Use of `FlutterEngineGroup` instead of simply using `FlutterEngine` HOT 1
- Overlay stops sending messages to UI when it's turned on after previously being closed after app termination
- Unable to create multiple overlay window. HOT 4
- Please add more flags to show when phone is looked HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_overlay_window.