Open palucdev opened 4 years ago
For everyone interested, I managed to get it to work overriding configureFlutterEngine()
method of io.flutter.embedding.android.FlutterActivity
in the MainAcrivity
class:
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
Intent intent = getIntent();
handleSendText(intent);
new MethodChannel(getFlutterView(), "app.channel.shared.data").setMethodCallHandler(
(call, result) -> {
if (call.method.contentEquals("getSharedText")) {
result.success(sharedText);
sharedText= null;
}
}
);
}
void handleSendText(Intent intent) {
sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
}
BinaryMessenger getFlutterView() {
return getFlutterEngine().getDartExecutor().getBinaryMessenger();
}
Still it will be good to update official docs :)
This issue is filed against flutter.dev, so should be moved to that repo.
@xster, do we have a solution for Kotlin?
I just checked the code in https://docs.flutter.dev/get-started/flutter-for/android-devs#how-do-i-handle-incoming-intents-from-external-applications-in-flutter, and it works as expected! looks like someone already fixed it but forgot to close this issue.
The only thing that could be improved is migrating the sample code to Kotlin, but I am not sure if is there a general goal to have all Java samples migrated to Kotlin on the website.
Hello!
I have simple communication case where android application is launching flutter application with intent containing some extra string data (using
putExtra()
method). Found official docs with guide how to handle such situations but unfortunetaly provided code from docs do not work as it usesio.flutter.app.FlutterActivity
package.Using
io.flutter.embedding.android.FlutterActivity
results in problem withGeneratedPluginRegistrant.registerWith(this);
line, as.registerWith()
expects to haveFlutterEngine
param, notMainActivity
one.Using suggested code for
io.flutter.embedding.android.FlutterActivity
:results in problem with MethodChannel seen below (do I still need to call some registration method in
onCreate()
)?Can someone provide me with usable solution on how to handle Intents in Flutter (v1.12.13+hotfix.9)? It will be good to update docs too, now it is more confusing than helpful.
Thanks in advance!