Installation
Add carp_apps_package to a CAMS app and configure the Android manifest.
The package needs the CARP Mobile Sensing (CAMS) setup, one Android permission and a setting that the participant turns on.
Android only
The package supports Android only, so iOS needs no setup. On iOS, CAMS skips the measures.
Set up the package in three steps:
Configure Android
Declare the
toolsnamespace and the usage statistics permission inandroid/app/src/main/AndroidManifest.xml:android/app/src/main/AndroidManifest.xml PACKAGE_USAGE_STATSlets the app read Android's usage statistics forAPP_USAGE. Android grants it only through the Usage access setting, not in a dialog.tools:ignore="ProtectedPermissions"suppresses the Android lint error for this protected permission.The
installed_appsplugin addsQUERY_ALL_PACKAGESandREQUEST_DELETE_PACKAGESto the merged manifest.APPSneedsQUERY_ALL_PACKAGESto see all apps on Android 11 or later. The package never uninstalls apps, so you can removeREQUEST_DELETE_PACKAGES:android/app/src/main/AndroidManifest.xml Register the sampling package
Register the package in
main(), before you configure the client:Call
CarpMobileSensing.ensureInitialized()beforeregister(): registering a sampling package before CAMS is initialized throws a null check error.Registering makes the two measure types and their data classes known to CAMS.
configure()restores the studies saved on the phone and needs these classes to read them.
Usage access
APP_USAGE reads usage statistics only after the participant turns on Usage access for the app in Android settings:
- CAMS does not ask for it, and
permission_handlercannot request it. - When access is missing, the
app_usageplugin opens the Usage access settings screen each time the measure collects. The measurement then has an emptyusagemap. - The package cannot check whether access is granted.
Explain the setting to participants before the first collection, for example during onboarding. Until they turn access on, a frequent trigger opens the settings screen again and again. The labels on the settings screen may differ between phone makers.
Google Play policy
Google Play restricts QUERY_ALL_PACKAGES. Its policy for this permission allows it only for apps whose core purpose is to discover all installed apps.
The policy names device search, antivirus apps, file managers and browsers as examples, and research studies are not among the permitted uses it lists. Apps that use the permission must also declare it in Play Console and follow Google's User Data policy, including prominent disclosure and consent.
If you publish on Google Play and cannot justify the permission, remove it from the build that you publish:
Without it, Android 11 or later shows the app only a limited set of other apps, so APPS lists fewer apps. With build flavors, keep the permission in development builds and remove it in the manifest of the Play Store flavor.
Troubleshooting
Turn on Usage access for the app in Android settings. Measurements collected before access was granted stay empty. Apps without foreground time in the window are always left out of usage.
Check that the merged manifest contains QUERY_ALL_PACKAGES, for example in the Merged Manifest tab of Android Studio. Without it, Android 11 or later hides most apps. System apps and apps without a launcher entry are never in the list.
Use an Android phone: the package supports Android only, and CAMS skips both measures on iOS.
Next step
Quickstart
Build an app that collects both measures and prints them.