我正在构建一个Flutter应用程序,该应用程序本质上是从云中获取数据的。数据类型各不相同,但它们通常是图像,pdf,文本文件或存档文件(zip文件)。
现在,我想触发一个隐式意图,以便用户可以选择自己喜欢的应用程序来处理有效负载。
我已经搜索了答案,并且尝试了以下路线:
路线3并不是我真正想要的,因为它使用的是平台的“共享”机制(即在Twitter上发布/发送给联系人),而不是打开有效负载。
1号和2号公路的运作方式……以一种不稳定,怪异的方式。我稍后再解释。
这是我的代码流:
import 'package:url_launcher/url_launcher.dart';
// ...
// retrieve payload from internet and save it to an External Storage location
File payload = await getPayload();
String uriToShare = samplePayload.uri.toString();
// at this point uriToShare looks like: 'file:///storage/emulated/0/jpg_example.jpg'
uriToShare = uriToShare.replaceFirst("file://", "content://");
// launch url
if (await canLaunch(uriToShare)) {
await launch(uriToShare);
} else {
throw "Failed to launch $uriToShare";
Run Code Online (Sandbox Code Playgroud)
上面的代码是使用url_launcher插件。如果我使用的是android_intent插件,那么最后几行代码将变为:
// fire intent
AndroidIntent intent = AndroidIntent(
action: "action_view", …Run Code Online (Sandbox Code Playgroud)