Search code examples
flutterflutter-dependencies

Launching and Navigating to Flutter App on Sharing Text to it from Browser


I am trying to make a flutter app that will receive text from a browser, if a person selects some text in the browser then a context menu opens, name of my app is shown in that context menu along with other options like cut, copy, etc and when the app name is tapped I want automatic launching and navigating of my app if it is not already running whereas if it is already running then by tapping it from context menu it should automatically be navigated to it and then in both cases selected text should be displayed in my app.

I am very new to Flutter. I have used flutter_process_text package to receive the text from the browser but it automatically triggers and navigates to my app when it is not running in the background and then displays the text but when the app is already running it shares the text as a stream but does not navigates to it automatically instead I have to open my app manually then the shared text gets displayed.


Solution

  • If you go into library code for android there is a function written -

    public static void listenProcessTextIntent(boolean isAppRunning) {
        if (!isAppRunning) {
          // Open app when its not running
          openApp();
        } else {
          // Fetch process text when the app is running.
          EventCallHandlerImplementation.onProcessTextChanged();
        }
        // Activity launch Theme.NoDisplay
        activity.finish();
      }
    

    So, seems like library is implemented to work in this way. if you want to change the behaviour then take the fork of library and add your custom code to

    FlutterProcessTextPlugin.java

    to openApp() in every case and it will work as expected.