X-SLAYER / flutter_overlay_window

Flutter plugin for displaying flutter app over other apps on the screen
https://pub.dev/packages/flutter_overlay_window
MIT License
94 stars 98 forks source link

Open the main app from floating window? #108

Open ducviet321 opened 1 month ago

ducviet321 commented 1 month ago

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);
    }
macdo-py commented 1 month ago

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!

ducviet321 commented 1 month ago

@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);
            }
macdo-py commented 1 month ago

@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!

ducviet321 commented 1 month ago

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