|
| 1 | +# tizen_app_manager |
| 2 | + |
| 3 | + [](https://pub.dev/packages/tizen_app_manager) |
| 4 | + |
| 5 | +Tizen application manager API. Used for getting installed app info and getting running context info of specific app. |
| 6 | + |
| 7 | +## Usage |
| 8 | + |
| 9 | +To use this package, add `tizen_app_manager` as a dependency in your `pubspec.yaml` file. |
| 10 | + |
| 11 | +```yaml |
| 12 | +dependencies: |
| 13 | + tizen_app_manager: ^0.1.0 |
| 14 | +``` |
| 15 | +
|
| 16 | +### Retrieving current app info |
| 17 | +
|
| 18 | +To retrieve information of the current app, get app ID with `currentAppId` and then get `AppInfo` with `getAppInfo` method. |
| 19 | + |
| 20 | +```dart |
| 21 | +var appId = await AppManager.currentAppId; |
| 22 | +var appInfo = await AppManager.getAppInfo(appId); |
| 23 | +``` |
| 24 | + |
| 25 | +### Retrieving all apps info |
| 26 | + |
| 27 | +To retrieve information of all apps installed on a Tizen device, use `getInstalledApps` method. |
| 28 | + |
| 29 | +```dart |
| 30 | +var apps = await AppManager.getInstalledApps(); |
| 31 | +for (var app in apps) { |
| 32 | + // Handle each app's info. |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +### Getting app running context |
| 37 | + |
| 38 | +To get specific app running context, create `AppRunningContext` instance. |
| 39 | + |
| 40 | +```dart |
| 41 | +var appId = await AppManager.currentAppId; |
| 42 | +var appContext = AppRunningContext(appId: appId); |
| 43 | +``` |
| 44 | + |
| 45 | +### Monitoring app events |
| 46 | + |
| 47 | +You can listen for app state change by subscribing to the stream. |
| 48 | + |
| 49 | +```dart |
| 50 | +final List<StreamSubscription<AppRunningContext>> _subscriptions = |
| 51 | + <StreamSubscription<AppRunningContext>>[]; |
| 52 | +
|
| 53 | +@override |
| 54 | +void initState() { |
| 55 | + super.initState(); |
| 56 | +
|
| 57 | + _subscriptions.add(AppManager.onAppLaunched |
| 58 | + .listen((AppRunningContext event) { |
| 59 | + // Handle the launched event. |
| 60 | + ... |
| 61 | + event.dispose(); |
| 62 | + })); |
| 63 | + _subscriptions.add(AppManager.onAppTerminated |
| 64 | + .listen((AppRunningContext event) { |
| 65 | + // Handle the terminated event. |
| 66 | + ... |
| 67 | + event.dispose(); |
| 68 | + })); |
| 69 | +} |
| 70 | +
|
| 71 | +@override |
| 72 | +void dispose() { |
| 73 | + super.dispose(); |
| 74 | +
|
| 75 | + _subscriptions.forEach((StreamSubscription subscription) => subscription.cancel()); |
| 76 | + _subscriptions.clear(); |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +## Required privileges |
| 81 | + |
| 82 | +The following privilege is required to invoke `AppRunningContext.resume()`. Add required privileges in `tizen-manifest.xml` of your application. |
| 83 | + |
| 84 | +```xml |
| 85 | +<privileges> |
| 86 | + <privilege>http://tizen.org/privilege/appmanager.launch</privilege> |
| 87 | +</privileges> |
| 88 | +``` |
0 commit comments