How can I open a specific URL of the PlayStore/AppStore with flutter on Android and IOS, depending on which smartphone it is executed? I mean I want to open the application and not a browser or something like this.
In this thread I found some native way for android but how can I do this with flutter?
final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); } catch (android.content.ActivityNotFoundException anfe) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName))); }
If there is currently no way to do this, it would be a nice feature to implement for the plugin url_launcher.
The URL Launcher is a Flutter plugin that allows your applications to launch web browsers, map applications, dialer applications, mail applications, and so on. The URL Launcher plugin works by creating intents to open applications using different URL schemes.
Android. We use the Application ID (package name) to identify your app inside our system. You can find this in the app's Play Store URL after 'id'. For example, in https://play.google.com/store/apps/details?id=com.company.appname the identifier would be com.
You can use this Library,
Basically, To use this plugin, add launch_review
as a dependency in your pubspec.yaml file.
launch_review: ^1.0.1
To use :
import 'package:launch_review/launch_review.dart';
Then invoke the static launch method of LaunchReview anywhere in your Dart code. If no arguments are provided, it will consider the current package.
LaunchReview.launch();
To open the App Store page for any other applications, you can pass the app Id.
LaunchReview.launch(androidAppId: <package name>, iOSAppId: <ios app id>);
You can do something similar in flutter:
import 'package:url_launcher/url_launcher.dart'; try { launch("market://details?id=" + appPackageName); } on PlatformException catch(e) { launch("https://play.google.com/store/apps/details?id=" + appPackageName); } finally { launch("https://play.google.com/store/apps/details?id=" + appPackageName); }
The exception/catch does not seem to work for some reason so adding 'finally' did the trick, finally :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With