I’m getting the below exception while trying to switch to chrome browser from my app and unable to interact into the browser.
java.lang.SecurityException: Permission Denial: starting Intent { flg=0x10000000 cmp=com.android.chrome/org.chromium.chrome.browser.customtabs.CustomTabActivity } from null (pid=14572, uid=2000) not exported from uid 10108
at com.android.server.am.ActivityStackSupervisor.checkStartAnyActivityPermission(ActivityStackSupervisor.java:1682)
at com.android.server.am.ActivityStarter.startActivity(ActivityStarter.java:442)
at com.android.server.am.ActivityStarter.startActivityLocked(ActivityStarter.java:276)
at com.android.server.am.ActivityStarter.startActivityMayWait(ActivityStarter.java:835)
at com.android.server.am.ActivityManagerService.startActivityAndWait(ActivityManagerService.java:4740)
at com.android.server.am.ActivityManagerShellCommand.runStartActivity(ActivityManagerShellCommand.java:408)
at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:142)
at android.os.ShellCommand.exec(ShellCommand.java:96)
at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:15244)
at android.os.Binder.shellCommand(Binder.java:573)
Appium version (or git revision) that exhibits the issue: 1.10.0
Desktop OS/version used to run Appium: MAC
Mobile platform/version under test: Android 8.0
Real device or emulator/simulator: Moto x4
This is my code:
@BeforeSuite
public void setUpAppium() throws MalformedURLException {
final String URL_STRING = “http://127.0.0.1:4723/wd/hub”;
URL url = new URL(URL_STRING);
//Use a empty DesiredCapabilities object
DesiredCapabilities capabilities = new DesiredCapabilities();
File appdir = new File("/Users/apple/Documents/AndroidiOSBuilds/GammaPracticeApp/3.9.0GA/");
File app = new File(appdir, “CK12-debug-gamma-3.9.0.254808.apk”);
capabilities.setCapability(CapabilityType.BROWSER_NAME, “”);
capabilities.setCapability(“noReset”, true);
capabilities.setCapability(“autoWebview”, “true”);
capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 1000);
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
capabilities.setCapability(“autoLaunch”, Boolean.parseBoolean(“autolaunch”));
capabilities.setCapability(“autoLaunch”, Boolean.parseBoolean(String.valueOf(true)));
capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, “org.ck12.app.practice.MainActivity”);
capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, “org.ck12.app.practice”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
capabilities.setCapability(“recreateChromeDriverSessions”, true);
capabilities.setCapability(“nativeWebTap”, true);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “ZY224QJNRJ”); // Moto E TA38500ME6
capabilities.setCapability(“chromedriverExecutable”, “/Users/apple/Desktop/ChromeDriver/44/chromedriver”);
driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
try {
Thread.sleep(15000);
} catch (InterruptedException e) {
e.printStackTrace();
}
switchToWebViewContext(“NATIVE_APP”);
System.out.println(“switching the context to native”);
try {
if (driver.findElementById(“com.android.packageinstaller:id/permission_allow_button”).isDisplayed()) {
driver.findElementById(“com.android.packageinstaller:id/permission_allow_button”).click();
} else {
System.out.println(“Permission popup is not displayed”);
}
} catch (Exception e) {
e.printStackTrace();
}
switchToWebViewContext(“WEBVIEW”);
System.out.println(“switching the context to native”);
try {
Thread.sleep(15000);
} catch (InterruptedException e) {
e.printStackTrace();
}
switchApp();
return capabilities;
}
@Test
public boolean switchApp () {
if (driver.findElement(By.cssSelector(“a.sign-btn”)).isDisplayed()) {
driver.findElement(By.cssSelector(“a.sign-btn”)).click();
//driver.runAppInBackground(10);
try {
Thread.sleep(15000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
try {
System.out.println(“switching…”);
((AndroidDriver) driver).startActivity(“com.android.chrome”, “org.chromium.chrome.browser.customtabs.CustomTabActivity”);
switchToWebViewContext(“NATIVE_APP”);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(driver.getCurrentUrl());
switchToWebViewContext(“WEBVIEW”);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
((AndroidDriver) driver).startActivity(“org.ck12.app.practice”, “org.ck12.app.practice.MainActivity”);
System.out.println(driver.getCurrentUrl());
}catch (Exception e){
e.printStackTrace();
}
return true;
}