Skip to content

Commit 044cda8

Browse files
author
Fatme
authored
Merge pull request #3535 from NativeScript/vladimirov/expose-android-process-service
feat(API): Expose androidProcessService - getAppProcessId
2 parents f88549c + 6bb40de commit 044cda8

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

PublicAPI.md

+25
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const tns = require("nativescript");
4848
* [assetsGenerationService](#assetsgenerationservice)
4949
* [generateIcons](#generateicons)
5050
* [generateSplashScreens](#generatesplashscreens)
51+
* [androidProcessService](#androidprocessservice)
52+
* [getAppProcessId](#getappprocessid)
5153

5254
## Module projectService
5355

@@ -1125,6 +1127,29 @@ tns.assetsGenerationService.generateSplashScreens({ projectDir: "/Users/username
11251127
});
11261128
```
11271129
1130+
## androidProcessService
1131+
The `androidProcessService` exposes methods for getting information about the applications working on Android devices.
1132+
1133+
### getAppProcessId
1134+
The `getAppProcessId` returns the PID of the specified application. If the app is not running on device, the method will return null.
1135+
1136+
* Definition
1137+
```TypeScript
1138+
/**
1139+
* Gets the PID of a running application.
1140+
* @param deviceIdentifier {string} The identifier of the device.
1141+
* @param appIdentifier The identifier of the application.
1142+
* @return {string} Returns the process id matching the application identifier in the device process list.
1143+
*/
1144+
getAppProcessId(deviceIdentifier: string, appIdentifier: string): Promise<string>;
1145+
```
1146+
1147+
* Usage
1148+
```JavaScript
1149+
tns.androidProcessService.getAppProcessId("4df18f307d8a8f1b", "org.nativescript.demoapp")
1150+
.then(pid => console.log(`The PID is ${pid}`))
1151+
.catch(err => console.error(`Error while checking for PID: ${err}`));
1152+
```
11281153
11291154
11301155
## How to add a new method to Public API

test/nativescript-cli-lib.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ describe("nativescript-cli-lib", () => {
4747
],
4848
assetsGenerationService: [
4949
"generateIcons",
50-
"generateSplashScreens"
50+
"generateSplashScreens",
51+
],
52+
androidProcessService: [
53+
"getAppProcessId"
5154
]
5255
};
5356

0 commit comments

Comments
 (0)