import 'dart:typed_data'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; class AndroidAppService { static const platform = MethodChannel('deckers.thibault/aves/app'); static Future getAppNames() async { try { final result = await platform.invokeMethod('getAppNames'); return result as Map; } on PlatformException catch (e) { debugPrint('getAppNames failed with code=${e.code}, exception=${e.message}, details=${e.details}}'); } return {}; } static Future getAppIcon(String packageName, int size) async { try { final result = await platform.invokeMethod('getAppIcon', { 'packageName': packageName, 'size': size, }); return result as Uint8List; } on PlatformException catch (e) { debugPrint('getAppIcon failed with code=${e.code}, exception=${e.message}, details=${e.details}'); } return Uint8List(0); } static Future edit(String uri, String mimeType) async { try { await platform.invokeMethod('edit', { 'title': 'Edit with:', 'uri': uri, 'mimeType': mimeType, }); } on PlatformException catch (e) { debugPrint('edit failed with code=${e.code}, exception=${e.message}, details=${e.details}'); } } static Future open(String uri, String mimeType) async { try { await platform.invokeMethod('open', { 'title': 'Open with:', 'uri': uri, 'mimeType': mimeType, }); } on PlatformException catch (e) { debugPrint('open failed with code=${e.code}, exception=${e.message}, details=${e.details}'); } } static Future openMap(String geoUri) async { if (geoUri == null) return; try { await platform.invokeMethod('openMap', { 'geoUri': geoUri, }); } on PlatformException catch (e) { debugPrint('openMap failed with code=${e.code}, exception=${e.message}, details=${e.details}'); } } static Future setAs(String uri, String mimeType) async { try { await platform.invokeMethod('setAs', { 'title': 'Set as:', 'uri': uri, 'mimeType': mimeType, }); } on PlatformException catch (e) { debugPrint('setAs failed with code=${e.code}, exception=${e.message}, details=${e.details}'); } } static Future share(String uri, String mimeType) async { try { await platform.invokeMethod('share', { 'title': 'Share via:', 'uri': uri, 'mimeType': mimeType, }); } on PlatformException catch (e) { debugPrint('share failed with code=${e.code}, exception=${e.message}, details=${e.details}'); } } }