install_referrer

Pub

一个Flutter插件,允许您检测您的应用程序是如何安装的。

支持的平台

  • Android: ✅
  • iOS: ✅

欢迎提交PR以支持新平台。

安装

  1. install_referrer: ^1.2.1添加到您的pubspec.yaml文件中。
  2. 导入import 'package:install_referrer/install_referrer.dart';
  3. 通过调用Future InstallReferrer.referrer来获取值

可能的值

Android

存储 Value
Google Play InstallationAppReferrer.androidGooglePlay
亚马逊应用商店 InstallationAppReferrer.androidAmazonAppStore
华为应用市场 InstallationAppReferrer.androidHuaweiAppGallery
Oppo应用市场 InstallationAppReferrer.androidOppoAppMarket
三星应用商店 InstallationAppReferrer.androidSamsungAppShop
Vivo应用商店 InstallationAppReferrer.androidVivoAppStore
小米应用商店 InstallationAppReferrer.androidXiaomiAppStore
其他 InstallationAppReferrer.androidManually

如果应用程序是从第三方应用(例如Gmail、Google Drive、Chrome…)安装的,它将被视为手动安装InstallationAppReferrer.androidManually)。

如果应用程序是从设备上未预装的应用商店(如FDroid、Amazon App Shop…)安装的(一个“非系统”应用),它也将被视为手动安装InstallationAppReferrer.androidManually)。

如果Android应用程序处于调试模式,它将被标记为InstallationAppReferrer.androidDebug

iOS

存储 Value
App Store InstallationAppReferrer.iosAppStore
Test Flight InstallationAppReferrer.iosTestFlight

如果iOS应用程序处于调试模式(例如,从模拟器安装),它将被标记为InstallationAppReferrer.iosDebug

包名

您也可以通过调用InstallReferrer.app来获取包名(Android)或应用ID(iOS)。

小部件

如果您想直接在Widget中接收结果,有两种选择:InstallReferrerDetectorListenerInstallReferrerDetectorBuilder

InstallReferrerDetectorBuilder(
  builder: (BuildContext context, InstallationApp? app) {
    if (app == null) {
      return const CircularProgressIndicator.adaptive();
    } else {
      return Text(
        'Package name:\n${app.packageName ?? 'Unknown'}\n'
        'Referrer:\n${referrerToReadableString(app.referrer)}',
          textAlign: TextAlign.center,
      );
    }
  },
);
InstallReferrerDetectorListener(
  child: YourWidget(),
    onReferrerAvailable: (InstallationApp? app) {
      // TODO
    },
);

GitHub

https://github.com/g123k/flutter_plugin_install_referrer