Ward Abbass
16646e7c88
Add support for getLaunchArgs on Android (#5466)
Add support for getLaunchArgs on Android
**Usage:**
1. **Pass** args in order to run the application on the device using ADB or xcrun or Detox:
- Detox: `device.launchApp(bundleId,{launchArgs: {'-key1': 'val1'}})` must use launchArgs key, see [docs](https://github.com/wix/Detox/blob/master/docs/APIRef.DeviceObjectAPI.md#7-additional-launch-arguments).
- ADB: `adb shell am start -n com.yourpackage/com.yourpackage.YourActivity --es launchArgs "{some stringyfied json}"`
- Xcrun: `/usr/bin/xcrun simctl launch ${udid} ${bundleId} --args -key1 value1 -key2 value2`
2. **Retrieve** the arguments: `const launchArgs = await Navigation.getLaunchArgs();`
- There is a small difference between platforms on how they pass the launch args:
- on iOS, the args will be passed as an array of pairs (argv,argc)
- on Android, the args will be passed in the form of a dictionary
Extract args as a dictionary example:
```javascript
const launchArgs = await Navigation.getLaunchArgs();
let resultArgs = {};
if (Platform.OS === 'android') {
resultArgs = launchArgs; // no need to proccess its a dictionary
} else {
for (let i = 0; i < launchArgs.length; i += 2) {
if (i + 1 < launchArgs.length) {
resultArgs[launchArgs[i]] = launchArgs[i + 1];
}
}
}
```