victorbonnet / flutter_web_browser

Plugin for flutter to open web page with Chrome Custom Tabs and SFSafariViewController
MIT License
62 stars 39 forks source link

Android: Browser selection improvements #28

Closed felix-barz-brickmakers closed 3 years ago

felix-barz-brickmakers commented 3 years ago

This PR adds 2 improvements. I created a single PR since they depend on each other. If prefered, I can split it into two:

  1. If the users default browser does not support custom tabs, the library will now try to fallback to using google chrome. If chrome is not installed, the default browser will be opened instead as seperate activity.
  2. Added FlutterWebBrowser.warmup(), which will warmup the browser engine used to open a custom tab, leading to much faster page loading. Does nothing on iOS
victorbonnet commented 3 years ago

Interesting PR!

There is a conflict in MethodCallHandlerImpl.java, could you please resolve it so that I can merge?

felix-barz-brickmakers commented 3 years ago

Done! All conflicts resolved.

victorbonnet commented 3 years ago

I have an exception when I test on my x86 android emulator.

E/MethodChannel#flutter_web_browser(11050): Failed to handle method call
E/MethodChannel#flutter_web_browser(11050): java.lang.IllegalStateException: Reply already submitted
E/MethodChannel#flutter_web_browser(11050):     at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:155)
E/MethodChannel#flutter_web_browser(11050):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.notImplemented(MethodChannel.java:248)
E/MethodChannel#flutter_web_browser(11050):     at dev.vbonnet.flutterwebbrowser.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:32)
E/MethodChannel#flutter_web_browser(11050):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/MethodChannel#flutter_web_browser(11050):     at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#flutter_web_browser(11050):     at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:693)
E/MethodChannel#flutter_web_browser(11050):     at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#flutter_web_browser(11050):     at android.os.MessageQueue.next(MessageQueue.java:335)
E/MethodChannel#flutter_web_browser(11050):     at android.os.Looper.loop(Looper.java:183)
E/MethodChannel#flutter_web_browser(11050):     at android.app.ActivityThread.main(ActivityThread.java:7656)
E/MethodChannel#flutter_web_browser(11050):     at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter_web_browser(11050):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/MethodChannel#flutter_web_browser(11050):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/DartMessenger(11050): Uncaught exception in binary message listener
E/DartMessenger(11050): java.lang.IllegalStateException: Reply already submitted
E/DartMessenger(11050):     at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:155)
E/DartMessenger(11050):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:253)
E/DartMessenger(11050):     at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/DartMessenger(11050):     at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:693)
E/DartMessenger(11050):     at android.os.MessageQueue.nativePollOnce(Native Method)
E/DartMessenger(11050):     at android.os.MessageQueue.next(MessageQueue.java:335)
E/DartMessenger(11050):     at android.os.Looper.loop(Looper.java:183)
E/DartMessenger(11050):     at android.app.ActivityThread.main(ActivityThread.java:7656)
E/DartMessenger(11050):     at java.lang.reflect.Method.invoke(Native Method)
E/DartMessenger(11050):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/DartMessenger(11050):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
felix-barz-brickmakers commented 3 years ago

I was missing a break; in the android method handler. Should be fixed now