I wrote a basic script using appium to launch an application, It works great for some applications but it will give an error when I try to launch some applications I tried my script with two applications
I found out the appPackage and appActivity values through adb(android debug bridge) tool
Angry Birds App
mCurrentFocus=Window{11fff76 u0 com.rovio.angrybirdsrio/com.rovio.fusion.App}
Medium App
mCurrentFocus=Window{af3c82 u0 com.medium.reader/com.medium.android.donkey.read.HomeActivity5}
here is the script that I wrote
public static void main(String[] args) throws MalformedURLException,InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "8.1.0");
capabilities.setCapability("deviceName", "Android SDK built for x86");
capabilities.setCapability("udid", "emulator-5554");
capabilities.setCapability("appPackage", "com.medium.reader");
capabilities.setCapability("appActivity", "com.medium.android.donkey.read.HomeActivity5 t69");
capabilities.setCapability("noReset", "true");
capabilities.setCapability("autoWebview", "true");
URL url = new URL("http://0.0.0.0:4723/wd/hub");
AppiumDriver<WebElement> driver = new AndroidDriver<WebElement>(url,capabilities);
driver.context("com.medium.android.donkey.read.HomeActivity5");
}
When I use the appPackage and appActivity for the Angry Birds app the app will launch in the emulator without any issue , but if I use the appPackage and appActivity for the medium app the script will give an java.lang.SecurityException: Permission Denial: starting Intent error
After trying to fix the issue I found out that I have to set android:exported="true" in the AndroidManifest.xml , Im not sure wether I can do this because i do not have the source code for any of the applications that Im trying to automate
Another suggestion was to try to launch the application through adb (android device bridge), I tried launching both application applications through adb which gave the same result Angry birds app was launched without any issue but the Medium app was not launched here is the error
java.lang.SecurityException: Permission Denial: starting Intent { flg=0x10000000 cmp=com.medium.reader/com.medium.android.donkey.read.HomeActivity5 } from null (pid=16084, uid=2000) not exported from uid 10084
at com.android.server.am.ActivityStackSupervisor.checkStartAnyActivityPermission(ActivityStackSupervisor.java:1632)
at com.android.server.am.ActivityStarter.startActivity(ActivityStarter.java:438)
at com.android.server.am.ActivityStarter.startActivityLocked(ActivityStarter.java:278)
at com.android.server.am.ActivityStarter.startActivityMayWait(ActivityStarter.java:817)
at com.android.server.am.ActivityManagerService.startActivityAndWait(ActivityManagerService.java:4625)
at com.android.server.am.ActivityManagerShellCommand.runStartActivity(ActivityManagerShellCommand.java:412)
at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:141)
at android.os.ShellCommand.exec(ShellCommand.java:96)
at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:15014)
at android.os.Binder.shellCommand(Binder.java:594)
at android.os.Binder.onTransact(Binder.java:492)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:4243)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2919)
at android.os.Binder.execTransact(Binder.java:697)
Can I launch any application through adb or appium?
You will get this kind of error when you try to launch the appActivity that is not main Activity.
You must put the main appActivity in your desired capability.
You can find the app activity using:
>adb shell
>dumpsys package | grep -i "app Package name here" | grep Activity
//for your case you can use:
>dumpsys package | grep -i com.rovio.angrybirdsrio | grep Activity
>dumpsys package | grep -i com.medium.reader | grep Activity