diff --git a/packages/tizen_app_control/example/integration_test/tizen_app_control_test.dart b/packages/tizen_app_control/example/integration_test/tizen_app_control_test.dart index 23592aee3..6609a71c9 100644 --- a/packages/tizen_app_control/example/integration_test/tizen_app_control_test.dart +++ b/packages/tizen_app_control/example/integration_test/tizen_app_control_test.dart @@ -26,6 +26,16 @@ void main() { expect(received.operation, 'http://tizen.org/appcontrol/operation/default'); }, timeout: kTimeout); + testWidgets('Can find matching applications', (WidgetTester _) async { + final AppControl request = AppControl( + operation: 'http://tizen.org/appcontrol/operation/view', + uri: 'file:///opt/usr/globalapps/$kAppId/shared/res/ic_launcher.png', + mime: 'image/*', + ); + final List matches = await request.getMatchedAppIds(); + expect(matches, isNotEmpty); + }, timeout: kTimeout); + testWidgets('Can send and receive request', (WidgetTester _) async { // Send a request to this app (the test runner itself). final AppControl request = AppControl( diff --git a/packages/tizen_app_control/example/lib/main.dart b/packages/tizen_app_control/example/lib/main.dart index fee1f6b5f..ffa5256ef 100644 --- a/packages/tizen_app_control/example/lib/main.dart +++ b/packages/tizen_app_control/example/lib/main.dart @@ -99,6 +99,13 @@ class _MyAppState extends State { 'http://tizen.org/appcontrol/data/text': 'Some text', }, ); + final List matches = await request.getMatchedAppIds(); + if (matches.isEmpty) { + _messengerKey.currentState!.showSnackBar( + const SnackBar(content: Text('No application found.')), + ); + return; + } await request.sendLaunchRequest(); } @@ -108,6 +115,13 @@ class _MyAppState extends State { mime: 'image/*', launchMode: LaunchMode.group, ); + final List matches = await request.getMatchedAppIds(); + if (matches.isEmpty) { + _messengerKey.currentState!.showSnackBar( + const SnackBar(content: Text('No application found.')), + ); + return; + } await request.sendLaunchRequest( replyCallback: ( AppControl request, diff --git a/packages/tizen_app_control/lib/app_control.dart b/packages/tizen_app_control/lib/app_control.dart index 535a45538..69542e838 100644 --- a/packages/tizen_app_control/lib/app_control.dart +++ b/packages/tizen_app_control/lib/app_control.dart @@ -144,6 +144,16 @@ class AppControl { .map((dynamic event) => ReceivedAppControl._fromMap( Map.from(event as Map))); + /// Returns a list of installed applications that can handle this request. + Future> getMatchedAppIds() async { + await _setAppControlData(); + + final Map args = {'id': _id}; + final dynamic response = + await _methodChannel.invokeMethod('getMatchedAppIds', args); + return List.from(response as List); + } + /// Sends a launch request to an application. /// /// The `http://tizen.org/privilege/appmanager.launch` privilege is required @@ -197,9 +207,7 @@ class AppControl { Future sendTerminateRequest() async { await _setAppControlData(); - final Map args = { - 'id': _id, - }; + final Map args = {'id': _id}; await _methodChannel.invokeMethod('sendTerminateRequest', args); }