getInstalledApplications method

Future<List<Application>> getInstalledApplications(
  1. {bool includeSystemApps = false,
  2. bool includeAppIcons = false,
  3. bool onlyAppsWithLaunchIntent = false}
)

List installed applications on the device includeSystemApps will also include system apps (or pre-installed) like Phone, Settings... includeAppIcons will also include the icon for each app (be aware that this feature is memory-heaving, since it will load all icons). To get the icon you have to cast the object to ApplicationWithIcon onlyAppsWithLaunchIntent will only list applications when an entrypoint. It is similar to what a launcher will display

Implementation

static Future<List<Application>> getInstalledApplications(
    {bool includeSystemApps: false,
    bool includeAppIcons: false,
    bool onlyAppsWithLaunchIntent: false}) async {
  return _channel.invokeMethod('getInstalledApps', <String, bool>{
    'system_apps': includeSystemApps,
    'include_app_icons': includeAppIcons,
    'only_apps_with_launch_intent': onlyAppsWithLaunchIntent
  }).then((Object apps) {
    if (apps != null && apps is List) {
      List<Application> list = <Application>[];
      for (Object app in apps) {
        if (app is Map) {
          try {
            list.add(Application._(app));
          } catch (e) {
            if (e is AssertionError) {
              print('[DeviceApps] Unable to add the following app: $app');
            } else {
              print('[DeviceApps] $e');
            }
          }
        }
      }

      return list;
    } else {
      return List<Application>.empty();
    }
  }).catchError((Object err) {
    print(err);
    return List<Application>.empty();
  });
}