Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Open AppStore/PlayStore URL

Tags:

flutter

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.

like image 742
GreenTigerEye Avatar asked Apr 06 '18 04:04

GreenTigerEye


People also ask

Can Open URL on Flutter?

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.

How do I find my app store URL?

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.


2 Answers

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>); 
like image 132
Naroju Avatar answered Sep 22 '22 11:09

Naroju


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 :)

like image 42
K Vij Avatar answered Sep 20 '22 11:09

K Vij