flutter_overlay_window icon indicating copy to clipboard operation
flutter_overlay_window copied to clipboard

Open the main app from floating window?

Open ducviet321 opened this issue 1 year ago • 8 comments

I'm looking for a better solution to open the main application from the floating window, right now I'm only able to archive this by modifying OverlayServices.java and call it as FlutterOverlayWindow.openMainApp();

    private void openMainApp() {
        Intent intent = new Intent();
        intent.setClassName("com.vitinc.myapp", "com.vitinc.myapp.MainActivity");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

ducviet321 avatar Apr 07 '24 04:04 ducviet321

Hi @ducviet321 , Im very interested in your idea / implementation, could not make it work, could you please explain a little more. The file you are referencing is: OverlayService.java? In wich line did you add your code? Do you need to do something else beside calling it as you said?

Thanks in advance!

macdo-py avatar Apr 15 '24 17:04 macdo-py

@macdo-py First you need to find your app namespace (maybe in android/app/src/main/kotlin/com/example/myapp/MainActivity.kt)

In /lib/src/overlay_window.dart add to class FlutterOverlayWindow

static Future<bool?> openMainApp() async {
    final bool? _res = await _overlayChannel.invokeMethod<bool?>('openMainApp');
    return _res;
  }

in android/src/main/java/flutter/overlay/window/flutter_overlay_window/OverlayService.java

Find flutterChannel.setMethodCallHandler((call, result) -> { and add below

            } else if (call.method.equals("resizeOverlay")) {
               ...
            } else if (call.method.equals("openMainApp")) {
                Intent intent = new Intent();
                intent.setClassName("com.vitinc. myapp", "com.vitinc.myapp.MainActivity");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }

ducviet321 avatar Apr 16 '24 07:04 ducviet321

@ducviet321 thank you so much for your help!!! it worked but I hag to remove the line Intent intent = new Intent(); And also, I'd like to know why you added a space in your app namespace, was it a typo o it should be like that.

Thanks again and best regards!

macdo-py avatar Apr 16 '24 12:04 macdo-py

Yeah it was my typo, maybe be you should rename intent variable instead of removing it, I haven't looked, just try to make it work quickly

ducviet321 avatar Apr 16 '24 12:04 ducviet321

use https://pub.dev/packages/android_intent_plus with app links

icanall10 avatar Jun 16 '24 06:06 icanall10

@icanall10 can you share example to open the app using android_intent_plus?

selvam920 avatar Aug 22 '24 11:08 selvam920

@selvam920 you should pre-configure app_links and then run

AndroidIntent intent = AndroidIntent(
      action: 'action_view',
      data: 'your-app-link-schema://your-app-link-host/some-path',
);

await intent.launch();

icanall10 avatar Aug 24 '24 08:08 icanall10

thanks

selvam920 avatar Sep 02 '24 07:09 selvam920