
[英]Why can't I get a list of installed apps for Android in Flutter?
[英]Is there a way in Flutter to show the list of installed apps to open a file with that works in IOS/Android?
我正在尝试在 flutter 中实现 open with 功能,允许用户选择应用程序来打开文件,并且在 iOS/Android 中都可以使用。
我面临的问题是我需要从设备获取已安装的应用程序,而我发现的插件在 IOS 中不起作用。
这些插件允许我安装已安装的应用程序,但它们仅适用于 Android。
这可能适用于打开应用程序,但我需要确切的名称。
与 Android 不同,Apple 不提供 API 来获取兼容的应用程序。 您需要进行实施以显示可用的应用程序并自行启动它们。 就我个人而言,我已经做了一些类似于打开其他地图应用程序而不是 Apple Plans 的事情,所以这绝对是可能的。
您可以使用包url_launcher及其方法canLaunch
通过尝试启动应用程序的 URL 方案来检查特定应用程序是否可用。 例如,Google Drive 的 URL 方案为googledrive://
因此如果我想检查 Google Drive 的可用性,我需要执行以下操作:
import 'package:url_launcher/url_launcher.dart';
bool isAvailable = await canLaunch('googledrive://');
然后我可以使用具有所需参数的相同 URL 方案打开它:
import 'package:url_launcher/url_launcher.dart';
await launch('googledrive://docs.google.com/document/<my_document_url>');
但是您需要自己定义您的应用程序中支持的所有应用程序,并且您必须根据可用的应用程序在 Flutter 中动态创建选择模式。
我想我已经找到答案了,插件open_file支持 Android 和 iOS 以及多种文件扩展名,您只需要指定文件的路径,它就会使用默认应用程序打开,如果您有多个应用程序能够打开文件,操作系统将显示带有应用程序的打开方式对话框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.