android - 如何以编程方式从我的 Flutter 应用程序启动应用程序?
问题描述
我知道这里可能有一些重复,但我发现的其他解决方案并不能完全满足我的需要。我想要做的是启动一个特定的应用程序,如果没有安装它,在 Playstore 和 AppStore 上启动应用程序页面,如果使用 iPhone。我已经接近完成这项工作,但我需要一些帮助才能越线。
我有一个加载所选应用程序的 FloatingAction 按钮,如果未安装,则加载 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!");
}
}
谢谢
解决方案
推荐阅读
- ajax - laravel7 工作图像上传,但 ajax 说有错误
- php - 如何使用子主题使以下标题以 h4 标签而不是 h2 输出标题?
- vb.net - 在键盘中按下 Enter 时更改按钮的背景颜色
- powerbi - 根据切片器日期使sql查询动态化
- c++ - 如何从源代码构建 glibcxx 3.4.21?
- cocoapods - 在 Swift 项目中包含 SQLCipher pod 时如何避免构建错误?
- python - Google 趋势 - 如果 isPartial 为真,则删除最后一行
- xquery - 如何在 xquery 中验证 ContextItem
- django - 为什么我的应用没有在 GKE 的浏览器中加载
- mysql - 在 Sakila DB 中检索演员 id 及其姓名及其地址