Flutter Open AppStore/PlayStore URL

Gre*_*Eye 8 flutter

如何在Android和IOS上使用flutter打开PlayStore/AppStore的特定URL,具体取决于它执行的智能手机?我的意思是我想打开应用程序而不是浏览器或类似的东西.

在这个线程中,我发现了一些原生的android方式,但我怎么能用颤动呢?

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)));
}
Run Code Online (Sandbox Code Playgroud)

如果目前无法做到这一点,那么为插件url_launcher实现它将是一个很好的功能.

Iai*_*ith 72

您可以使用url_luncher并根据平台打开 url,如下所示:

import 'package:url_launcher/url_launcher.dart';

if (Platform.isAndroid || Platform.isIOS) {
  final appId = Platform.isAndroid ? 'YOUR_ANDROID_PACKAGE_ID' : 'YOUR_IOS_APP_ID';
  final url = Uri.parse(
    Platform.isAndroid
        ? "market://details?id=$appId"
        : "https://apps.apple.com/app/id$appId",
  );
  launchUrl(
    url,
    mode: LaunchMode.externalApplication,
  );
}
Run Code Online (Sandbox Code Playgroud)

笔记

  • 您可以从中获取您的 iOS 应用程序 ID,http://itunes.apple.com/lookup?bundleId=YOUR_BUNDLE_ID然后查找trackId
  • 这不适用于 iOS 模拟器,因为它们没有应用程序商店
  • 设置modeLaunchMode.externalApplication阻止safari 闪烁一秒钟


Roc*_*nat 10

这就像这个问题最流行的答案,但不需要说 Android 包。此外,此解决方案不会在 Android 上显示“请评价应用程序”的提示。

这取决于open_storepackage_info_plus

const appStoreId = "1234567890"; // Your app's App Store ID
final packageName = (await PackageInfo.fromPlatform()).packageName;

OpenStore.instance.open(
  androidAppBundleId: packageName,
  appStoreId: appStoreId,
);
Run Code Online (Sandbox Code Playgroud)


Nar*_*oju 9

您可以使用此

基本上,要使用此插件,请launch_review在您的pubspec.yaml文件中添加为依赖项。

launch_review: ^1.0.1
Run Code Online (Sandbox Code Playgroud)

使用方法:

 import 'package:launch_review/launch_review.dart'; 
Run Code Online (Sandbox Code Playgroud)

然后在Dart代码中的任意位置调用LaunchReview的静态启动方法。如果未提供任何参数,它将考虑当前程序包。

LaunchReview.launch();
Run Code Online (Sandbox Code Playgroud)

要打开其他任何应用程序的“ App Store”页面,您可以传递应用程序ID。

LaunchReview.launch(androidAppId: <package name>,
                iOSAppId: <ios app id>);
Run Code Online (Sandbox Code Playgroud)

  • 现在它有 `writeReview` 选项,所以 `LaunchReview.launch(writeReview: false);` (3认同)

小智 6

您可以使用url_launcher包打开 appstore/playstore,如下所示:

      _launchURL(String url) async {
         if (await canLaunch(url)) {
             await launch(url);
         } 
         else {
             throw 'Could not launch $url';
         }
       }
Run Code Online (Sandbox Code Playgroud)


K V*_*Vij 5

你可以在颤振中做类似的事情:

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);        
}
Run Code Online (Sandbox Code Playgroud)

由于某种原因,异常/捕获似乎不起作用,所以添加“终于”成功了,最后:)

  • 无论是否发生异常,都会执行“finally”块。我怀疑您的代码尝试打开商店两次。 (3认同)
  • 您无法捕获返回“Future”的函数/方法中发生的异常,除非在调用它时放置“await”。 (2认同)