I am creating a small app that needs to be able to start completely separate apps automatically after registering certain triggers.
I have tried the following two methods to start the apps:
start activity
Intent i = ctx.getPackageManager().getLaunchIntentForPackage("package.name"); ctx.startActivity(i);
shell command
adb shell monkey -p package.name -c android.intent.category.LAUNCHER 1
The problem is that the first method only works if the screen is on and unlocked and the command can bring the app in the foreground. The second method, even though it starts the apps, the apps do not start their sub activities.
To put this in context, say I want to start a VPN app. The first method doesn't do anything if the screen is off or the phone is locked. The second command does start the app even with the phone locked and screen off, but the app does not start it's own VPN service/activity until I turn the screen on. In essence, the apps don't do anything (even though they do start) until the screen is on.
Any ideas how I can start an app and make sure it actually does what it normally does when it is started by actual human interaction, instead of just sitting idle?
The app will be used on a rooted Android 7.0 phone.