diff --git a/lib/commands/app-management.js b/lib/commands/app-management.js index 1827125f..47554987 100644 --- a/lib/commands/app-management.js +++ b/lib/commands/app-management.js @@ -55,11 +55,12 @@ commands.queryAppState = async function queryAppState (appId) { */ commands.activateApp = async function activateApp (appId) { this.log.debug(`Activating '${appId}'`); + const apiLevel = await this.adb.getApiLevel(); // Fallback to Monkey in older APIs - if (await this.adb.getApiLevel() < 24) { + if (apiLevel < 24) { + // The monkey command could raise an issue as https://stackoverflow.com/questions/44860475/how-to-use-the-monkey-command-with-an-android-system-that-doesnt-have-physical + // but '--pct-syskeys 0' could cause another background process issue. https://github.com/appium/appium/issues/16941#issuecomment-1129837285 const cmd = ['monkey', - // https://stackoverflow.com/questions/44860475/how-to-use-the-monkey-command-with-an-android-system-that-doesnt-have-physical - '--pct-syskeys', '0', '-p', appId, '-c', 'android.intent.category.LAUNCHER', '1']; @@ -77,7 +78,7 @@ commands.activateApp = async function activateApp (appId) { } const stdout = await this.adb.shell([ - 'am', 'start', + 'am', (apiLevel < 26) ? 'start' : 'start-activity', '-a', 'android.intent.action.MAIN', '-c', 'android.intent.category.LAUNCHER', // FLAG_ACTIVITY_REORDER_TO_FRONT | FLAG_ACTIVITY_BROUGHT_TO_FRONT | FLAG_ACTIVITY_NEW_TASK