gpt4 book ai didi

android - 如何以编程方式从Flutter应用程序中启动应用程序?

转载 作者:行者123 更新时间:2023-12-01 21:59:19 25 4
gpt4 key购买 nike

我了解这里可能存在一些重复,但是我发现的其他解决方案并不能完全满足我的需要。我要做的是启动一个特定的应用程序,如果未安装该应用程序,则在Playstore和AppStore上启动应用程序页面(如果使用iPhone)。我几乎可以使它正常工作,但是我需要一点帮助来解决问题。

我有一个FloatingAction Button,可以加载所选的应用程序,如果未安装,则可以加载PlayStore,但它不会直接转到应用程序页面。我尚未在iPhone上进行测试,因此,如果该代码是垃圾代码,那我也将不胜感激。

如何让我的应用程序直接进入playstore应用程序和appstore应用程序上的应用程序页面?

这是我的代码

import 'package:flutter/material.dart';
import 'dart:io';
import 'package:flutter_appavailability/flutter_appavailability.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('App Availability'),
),
body: FloatingActionButton(
backgroundColor: Colors.indigo,
onPressed: () => openApp(context),
child: Icon(Icons.open_in_new),
heroTag: "Open App",
),
),
);
}
}

void openApp(BuildContext context) {
try {
AppAvailability.launchApp(Platform.isIOS
? "appname://"
: "com.company.appname"
).then((_) {
print("App Launched!");
}).catchError((err) {
AppAvailability.launchApp(Platform.isIOS
? "appstore://"
: "com.android.vending"
)
// I think I will need to add package name to the playstore package name
// in the line above, but not sure how.
// I have tried com.android.vending?id=com.criticalarc.safezoneapp
// and com.android.vending/com.criticalarc.safezoneapp

.then((_) {});
print(err);
});
} catch (e) {
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text("App Not Installed!"),
),
);
print("App Not Installed!");
}
}

谢谢

最佳答案

关于android - 如何以编程方式从Flutter应用程序中启动应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60530015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com