I'm building Peerbeta, a service for Google Play's closed test: new personal developer accounts need 12 testers opted in for 14 days in a row before they can publish to production. Part of it is an Android app that testers install. Its main job sounds trivial: once a day, open the app being tested and record that it opened.
On Android 8, that's one line. On Android 11 and later, it took three different methods depending on the version, and one case with no method at all. Here is what works, in Kotlin, and why I ended up there.
Why open someone else's app at all
Google's rule has two parts. The first one everyone knows: at least 12 testers opted in for the 14 days before you apply. The second one is in the same help page: Google can ask you to keep testing for "fewer than 12 opted-in testers or insufficient tester engagement during the testing period" (Play Console Help).
Play Console shows the developer the opt-in count. It doesn't show whether tester number 7 stopped opening the app on day 3. Google doesn't publish how it measures engagement either, so I won't pretend to know the formula. What a developer can do is know, day by day, who actually used the app.
So the tester app opens the app under test, and the server records each open. The first successful open of a day counts that day for that tester. Three days without one marks the tester as at risk, early enough to remind them or replace them.
The constraint: package visibility
Since Android 11 (API 30), an app targeting API 30+ sees a filtered list of installed packages. getLaunchIntentForPackage("com.someone.app") returns null for a package you can't see, exactly as if it weren't installed.
The usual ways out didn't fit:
-
QUERY_ALL_PACKAGES: Google Play restricts it to apps whose core feature needs to see every installed app, behind a declaration. Even if a tester app could argue for it, I didn't want to ask people to install an app that can list everything on their phone. -
<queries>with package names: the app under test changes with every test. It can't be declared at build time.
So the manifest has neither. Here is what's left.
Android 13+: getLaunchIntentSenderForPackage
API 33 added PackageManager.getLaunchIntentSenderForPackage(). It returns an IntentSender for the package's launcher activity, and in our tests it isn't filtered by package visibility.
private fun startWithIntentSender(activity: Activity, packageName: String) {
val sender = activity.packageManager.getLaunchIntentSenderForPackage(packageName)
val options = if (Build.VERSION.SDK_INT >= 34) {
// Android 14+: explicitly allow the start, even though it comes from the foreground activity.
@Suppress("DEPRECATION")
ActivityOptions.makeBasic()
.setPendingIntentBackgroundActivityStartMode(
ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED
)
.toBundle()
} else null
activity.startIntentSender(sender, null, 0, 0, 0, options)
}
Two details:
- Android 14 tightened background activity launches: whoever sends an
IntentSenderorPendingIntentnow has to opt in to lend its own right to start activities. The tester app is in the foreground when it does this, so it opts in explicitly withActivityOptions. The constant is deprecated in newer API levels, hence the@Suppress. - You get a sender even for a package that isn't installed. The failure comes when you start it. In our tests a missing app ends in
ActivityNotFoundExceptionwhatever the method; we also catchIntentSender.SendIntentException. Both are recorded as "not installed", which is exactly the signal we want: we learn whether the app is there without ever querying the package list.
Android 11 and 12: name the activity
No IntentSender API on these versions. What does work is an explicit intent that names both the package and the launcher activity class:
activity.startActivity(
Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_LAUNCHER)
.setClassName(packageName, activityClass)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
)
The catch: you need the class name of the launcher activity, and you can't look it up, since that would mean seeing the package. So the developer types it when they create the test.
That field has its own trap. People copy it from the manifest, where it's usually shortened to .MainActivity. The obvious fix is to complete it with the package name, like the manifest does, and the tester app still does that:
internal fun qualify(packageName: String, launchActivity: String?): String? {
val name = launchActivity?.trim().orEmpty()
if (name.isEmpty()) return null
return if (name.startsWith(".")) packageName + name else name
}
But the class really lives under the Gradle namespace, which can differ from the applicationId. With applicationId "com.acme.notes.free" and namespace "com.acme.notes", .MainActivity becomes com.acme.notes.free.MainActivity, a class that doesn't exist. And a wrong class name fails exactly like a missing app. So the form now refuses a shortened name and asks for the full one, and it warns, without blocking, when the class sits outside the package, since that's legitimate in exactly this case.
Android 11 and 12 without the activity: no method
If the developer leaves the field empty, nothing in the tester app can open their app on Android 11 or 12. The fallback is manual: the tester opens the app themselves and sends a screenshot, and a person at Peerbeta checks it. Until it's approved, nothing counts: not the install, not the day.
Android 8 to 10
No visibility filtering, so the classic call works:
val intent = activity.packageManager.getLaunchIntentForPackage(packageName)
?: throw ActivityNotFoundException("no launch intent for $packageName")
activity.startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
The whole decision
fun plan(sdkInt: Int, packageName: String, launchActivity: String?): LaunchPlan {
val activity = qualify(packageName, launchActivity)
return when {
sdkInt >= 33 -> LaunchPlan(OpenMethod.INTENT_SENDER, packageName)
sdkInt >= 30 && activity != null -> LaunchPlan(OpenMethod.EXPLICIT_COMPONENT, packageName, activity)
sdkInt >= 30 -> LaunchPlan(OpenMethod.SCREENSHOT, packageName)
else -> LaunchPlan(OpenMethod.LAUNCH_INTENT, packageName)
}
}
| Android | Method | Needs |
|---|---|---|
| 13+ | getLaunchIntentSenderForPackage |
nothing |
| 11–12 | explicit intent | the launcher activity's full class name |
| 11–12 | screenshot reviewed by a person | nothing, but slower |
| 8–10 | getLaunchIntentForPackage |
nothing |
Each open is sent with its method and outcome (opened, not_installed, failed with the exception name), so a broken setup shows up as a pattern, not as a silent zero.
Is the phone real?
Each check can also carry a Play Integrity token. A device that doesn't meet device integrity, or a tester app that isn't the one from Google Play, feeds a risk score on the tester's device, along with signals like emulator model names. It doesn't decide alone; it tells us where to look.
What I learned about the 14 days
A few things that cost developers a test, collected while building this:
- Count day 1 from verified installs, not from invites. Invited testers take a day or two to opt in and install. If your 14 days start at the invite, you lose those days.
- A tester who opts out and back in starts a new 14 days. Replacing a tester has the same effect, so do it early.
- Keep testers out of your internal test track. Google says a user who opts into your internal test isn't eligible for your closed test.
- Ship an update during the test. Google recommends it, and the production form asks what you changed after feedback.
About Peerbeta
That tester app is the core of Peerbeta. There's a free route, a circle of 16 developers who test each other's apps for 14 days, and paid tests from $19 (20 testers invited) or $39 (25), paid once. The developer sees verified installs and who was active today, gets feedback on days 1, 7 and 14, and ends with a report and draft answers for Google's production form.
There are also free tools that need no account, like an opt-in link checker and a production access date calculator.
If you've found a cleaner way to launch an arbitrary app on Android 11 and 12 without QUERY_ALL_PACKAGES, I'd really like to hear it in the comments.
Top comments (1)
The Android 11-12 trap you describe is the part I would have missed — that .MainActivity expands with the Gradle namespace, not the applicationId, so with applicationId "com.acme.notes.free" and namespace "com.acme.notes" it becomes com.acme.notes.free.MainActivity, a class that does not exist, and it fails exactly like a missing app. Using getLaunchIntentSenderForPackage on Android 13+ to avoid QUERY_ALL_PACKAGES makes sense, and recording each open as opened, not_installed, or failed is a smart way to turn a silent zero into a pattern. When the 11-12 screenshot fallback is used, how do you handle a tester who opens the app but does not send the screenshot — does that day still count toward the 14 days, or does it stay unverified?