首页 > 解决方案 > 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 ?

标签: androidflutter

解决方案


找到了方法:包: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 编辑器。


推荐阅读