android - How to launch advanced download manager (ADM) app from a flutter app and give it download data?
问题描述
I am new to flutter and don't know much about android. I would like to have my flutter app allow users to launch ADM with download data to download files.Now I have tried different approaches but did seem to work. I have tried url_launcher which didn't launch
ListTile(
title: Text("ADM LAUNCH"),
onTap: () async {
String adm = "com.dv.adm";
if (await canLaunch(adm)) {
await launch(adm);
} else {
throw ("can't launch ");
}
},
),
I tried android intent as well:
ListTile(
title: Text("android intent"),
onTap: () async {
final AndroidIntent intent = AndroidIntent(
action: 'action_view',
package: 'com.dv.adm',
);
await intent.launch();
},
),
How can I start ADM from my app and pass in download argument ? also what kind of argument do I have to pass ? like link or url ?
解决方案
找到了方法:包:android意图,设备应用程序
首先将活动添加到应用程序标记中的 AndroidManifest.xml 中:
<!-- Android ADM intent -->
<activity android:name="com.dv.adm"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN">
</action>
</intent-filter>
</activity>
<!-- END OF ADM INTENT -->
颤振代码:
import 'package:device_apps/device_apps.dart';
import 'package:android_intent/android_intent.dart';
download(String url, String fileName) async {
bool isInstalled = await DeviceApps.isAppInstalled('com.dv.adm');
if (isInstalled) {
final AndroidIntent intent = AndroidIntent(
action: 'action_main',
package: 'com.dv.adm',
componentName: 'com.dv.adm.AEditor',
arguments: <String, dynamic>{
'android.intent.extra.TEXT': url,
'com.android.extra.filename': "$fileName.mp4",
},
);
await intent.launch().then((value) => null).catchError((e) => print(e));
} else {
// ask user to install the app
}
}
这将使用您提供的参数打开 ADM 编辑器。
推荐阅读
- reactjs - 如何在反应应用程序中压缩构建文件?
- c++ - 如何使这个大写小写 C++ 程序工作?
- python-3.x - Flask Restful api发布带有图像的数据
- html - 将图像放在导航栏引导程序和 css 下方,而不会被文本重叠
- vue.js - 组件正在渲染,但在测试时失败
- php - AWS S3 在客户端浏览器上显示文件
- python - 将 MATLAB 代码转换为 Python 后,我得到了不同的结果
- node.js - 请尝试重新编译或重新安装 Nodejs
- lisp - spacemacs 中 org-mode 代码结构“#+begin_src lisp”的问题
- php - 条件标签(is_shop()、is_product_category() 和 is_product())