Detect Esper-managed devices programmatically — check for Esper Agent package
Android
When building an Android application that runs on both Esper-managed devices and consumer devices, you may need to branch behavior at runtime based on whether Esper is managing the device. The most reliable way to do this is to check for the presence of the Esper Agent package.
Why this happens
Every Esper-managed Android device has the Esper Agent (io.shoonya.shoonyadpc) installed as part of enrollment. Consumer devices do not have this package. Querying for it with the Android PackageManager API gives you a definitive, runtime signal of Esper management with no dependency on device metadata or network calls.
Before you begin
- This method requires native Android code. If you are using React Native or another cross-platform framework, create a native Android module that bridges to the
PackageManagerAPI before following the steps below. - Confirm which Android API levels your app targets. The
AndroidManifest.xmlchange in Step 1 is required for API level 30 (Android 11) and above.
Steps
-
Declare package visibility in
AndroidManifest.xml.
Android 11 (API level 30) and above restrict which packages an app can query by default. Without an explicit declaration,getPackageInfo()will throwNameNotFoundExceptioneven when the Esper Agent is installed. Add a<queries>block inside your<manifest>tag:<manifest package="your.application.package"> <queries> <package android:name="io.shoonya.shoonyadpc" /> </queries> </manifest> -
Check for the Esper Agent package at runtime.
UsePackageManagerto attempt a package lookup. A successful lookup means the device is Esper-managed; aNameNotFoundExceptionmeans it is not. Use the implementation that matches your development language:
Kotlin:
Java:val isEsperManaged = try { packageManager.getPackageInfo("io.shoonya.shoonyadpc", 0) true } catch (e: PackageManager.NameNotFoundException) { false }boolean isEsperManaged = false; try { getPackageManager().getPackageInfo("io.shoonya.shoonyadpc", 0); isEsperManaged = true; } catch (PackageManager.NameNotFoundException e) { isEsperManaged = false; } -
Branch your application logic based on the result.
Use theisEsperManagedflag to enable or disable features specific to managed or consumer contexts:if (isEsperManaged) { // Device is Esper-managed — apply enterprise logic } else { // Device is not managed — apply consumer logic } -
Test the detection on both device types before releasing.
Install your app on a known Esper-enrolled device and confirmisEsperManagedreturnstrue. Then install the same build on a non-enrolled Android device and confirm it returnsfalse. Test on a device running Android 11 or above to validate the<queries>declaration is working correctly.
Verify: On an enrolled Esper device, your detection logic returns true immediately at runtime with no exceptions thrown. On a non-enrolled device, it returns false. Both results should be consistent across repeated launches.
If this doesn't resolve it
If the detection returns unexpected results, collect the following before contacting support:
- The Android API level of the test device (Settings → About Phone → Android version)
- Confirmation that the
<queries>block is present in the final compiledAndroidManifest.xml(check the merged manifest in Android Studio under app → manifests → Merged Manifest) - The full stack trace if an unexpected exception is thrown
- Whether the device is confirmed enrolled in Esper (visible in Devices & Groups in the Esper Console with an Active status)
Contact Esper Support with the above details.
Still need help?
If the steps above don't resolve the issue, submit a support ticket with your device model, Android version, Esper Agent version, and a description of what you've already tried — this helps the support team investigate without a follow-up.
Please sign in to leave a comment.
Comments
0 comments