Flutter Firebase 动态 link 在模拟器上导航到正确的路线,但在真实的 android 设备上却不行

Flutter Firebase dynamic link navigates to correct route on emulator but not on a real android device

我正在创建自定义动态 link,如下所示:

Future<String> generateDynamicLink(
    String pid, String imgurl, String title, String description) async {
  final DynamicLinkParameters parameters = DynamicLinkParameters(
    uriPrefix: uriPrefix,
    link: Uri.parse(
      uriPrefix+'/pd?pid=$pid',
    ),
    androidParameters: AndroidParameters(
      packageName: 'com.test',
      minimumVersion: 0,
    ),
    socialMetaTagParameters: SocialMetaTagParameters(
      description: description,
      imageUrl: Uri.parse(
        imgurl,
      ),
      title: title,
    ),
    dynamicLinkParametersOptions: DynamicLinkParametersOptions(
      shortDynamicLinkPathLength: ShortDynamicLinkPathLength.unguessable,
    ),
  );

  Uri url = await parameters.buildUrl();
  ShortDynamicLink shortenedLink = await DynamicLinkParameters.shortenUrl(
    url,
    DynamicLinkParametersOptions(
        shortDynamicLinkPathLength: ShortDynamicLinkPathLength.unguessable),
  );
  return shortenedLink.shortUrl.toString();
}

并通过在我主页的 initState 中调用 fetchLinkData(见下文)来处理接收部分

void fetchLinkData(BuildContext context) async {
  var link = await FirebaseDynamicLinks.instance.getInitialLink();
  handleLinkData(link, context);

  FirebaseDynamicLinks.instance.onLink(
    onSuccess: (PendingDynamicLinkData dynamicLink) async {
      handleLinkData(dynamicLink, context);
    },
    onError: (OnLinkErrorException error) async {
      print(error.message);
    },
  );
}

void handleLinkData(PendingDynamicLinkData data, BuildContext context) async {
  final Uri uri = data?.link;
  if (uri != null) {
    final queryParams = uri.queryParameters;
    if (queryParams.keys.contains("pid")) {
      String pid = queryParams["pid"];
      Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => ProductScreen(id: pid),
        ),
      );
    }
  }
}

现在我的问题是,在模拟器上,一切都按预期工作,当动态 link 打开时,它导航到正确的页面,但是当我在我的 android 设备上尝试时,只有应用程序被打开.

如果其他人遇到同样的问题,删除 Intent 过滤器可以解决我的问题。