-
Notifications
You must be signed in to change notification settings - Fork 124
Start service from native side (Kotlin/Java) #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It seems difficult to implement that way using this plugin. You will probably have to implement it yourself and use it. Here's the implementation I'm thinking of:
var rawValue = PluginUtilities.getCallbackHandle(callback)?.toRawHandle();
static const methodChannel = MethodChannel('your_package/method');
methodChannel.invokeMethod('setRawValue', rawValue);
private fun executeDartCallback(callbackHandle: Long?) {
// If there is no callback handle, the code below will not be executed.
if (callbackHandle == null) return
flutterEngine = FlutterEngine(this)
flutterLoader = FlutterInjector.instance().flutterLoader()
flutterLoader!!.startInitialization(this)
flutterLoader!!.ensureInitializationComplete(this, null)
val appBundlePath = flutterLoader!!.findAppBundlePath()
val callbackInfo = FlutterCallbackInformation.lookupCallbackInformation(callbackHandle)
val dartCallback = DartExecutor.DartCallback(assets, appBundlePath, callbackInfo)
flutterEngine!!.dartExecutor.executeDartCallback(dartCallback)
} With this implementation, it seems that only the code on the dart side can be executed without running the foreground service. If I have time, I'll help you implement it. |
Yeah, what i ended up doing is exactly this 👌 Thanks for help! |
HI!
I would like to use a foreground service to update my native Android widget (on home screen) - I have everything set up and figured out, except the part "how to start foreground service with some Dart running when received
onUpdate
in widget"Is there some nice
Intent
that I can just fire to start the service?The text was updated successfully, but these errors were encountered: