Installation
Add carp_communication_package to a CAMS app and configure Android and iOS.
The package builds on the CARP Mobile Sensing (CAMS) setup and adds the permissions that its measures need. Set it up in four steps:
Add the packages
The package runs on top of CAMS, so complete the CAMS setup in Installation first. The steps below add only what the communication measures need.
Configure Android
Each measure needs its own manifest entries, and CAMS asks the participant for one
permission_handlerpermission per measure:Measure Manifest entries CAMS asks for PHONE_LOGREAD_CALL_LOGandREAD_PHONE_STATE, whichcall_e_logadds by itselfPermission.phoneTEXT_MESSAGE_LOGREAD_SMSPermission.smsTEXT_MESSAGERECEIVE_SMSand theIncomingSmsReceiverreceiverPermission.phoneCALENDARREAD_CALENDARandWRITE_CALENDARPermission.calendarFullAccessAdd the permissions of the measures you use to
android/app/src/main/AndroidManifest.xml, directly above<application:android/app/src/main/AndroidManifest.xml The calendar needs both calendar permissions, although the package only reads:
permission_handleranddevice_calendar_plusrefuse calendar access unless both are declared.For
TEXT_MESSAGE, also declare the receiver ofanother_telephonyinside<application>. It passes incoming messages to the app:android/app/src/main/AndroidManifest.xml In version 2.1.0,
TEXT_MESSAGEadds no measurements. See Incoming text messages.On Android, CAMS starts a measure only when
permission_handlerreports its permission as granted.permission_handlerreports a group as granted only when the participant granted every permission of the group that the merged manifest declares. If your app or another plugin declares more phone permissions, such asCALL_PHONE, the participant must grant them too beforePHONE_LOGstarts.The package needs
minSdk24 or later. Ifandroid/app/build.gradle.ktssets a lower value, raise it to 24.Configure iOS
Only
CALENDARruns on iOS. Add the calendar usage descriptions toios/Runner/Info.plist:ios/Runner/Info.plist device_calendar_plusrefuses to read calendars withoutNSCalendarsUsageDescription, on every iOS version. iOS 17 or later shows theNSCalendarsFullAccessUsageDescriptiontext when the app asks for full calendar access.CAMS asks for calendar access through
permission_handler, which includes only the permissions your build enables:Swift Package Manager CocoaPods permission_handler_appleenables calendar access when it finds the two keys inInfo.plist, so no other change is needed. After you change the keys, delete Xcode's derived data once so that Xcode reads them again:Enable calendar access in the
post_installblock of the Podfile. If the block already setsGCC_PREPROCESSOR_DEFINITIONS, add the two macros to that list:ios/Podfile Without calendar access in
permission_handler, CAMS cannot ask when the study is deployed, and iOS asks the participant when the calendar measure first runs.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 the package makes its four measure types and the JSON types of their data known to CAMS. It also adds its privacy transformers to the default privacy schema.
configure()restores the studies saved on the phone and needs these types to read them.
Google Play policy
Google Play treats READ_SMS, RECEIVE_SMS, SEND_SMS and READ_CALL_LOG as restricted SMS and Call Log permissions. Only apps with an approved use can request them, and research is not one of the exceptions.
An app that collects calls or text messages can therefore be rejected. See Google Play's policy on SMS and Call Log permissions.
Two plugins add permissions to every app that depends on the package, also when it only collects the calendar:
| Plugin | Permissions it adds | Used by |
|---|---|---|
call_e_log | READ_CALL_LOG, READ_PHONE_STATE | PHONE_LOG |
another_telephony | ACCESS_COARSE_LOCATION | None in this package |
To publish an app that collects only the calendar, remove the restricted permissions from the merged manifest. Add the tools namespace to <manifest> and the marked lines:
tools:node="remove" drops a permission even when a plugin's manifest adds it. Use only CALENDAR in the protocols of such an app.
If no other package in the app uses location, remove ACCESS_COARSE_LOCATION the same way. To check the result, open AndroidManifest.xml in Android Studio and select the Merged Manifest tab.
Troubleshooting
Declare both READ_CALENDAR and WRITE_CALENDAR. With only one of them, permission_handler reports the calendar permission as denied, and device_calendar_plus refuses to read calendars.
Check that the participant granted every phone permission. In the Merged Manifest tab, look for phone permissions that the study does not need, such as CALL_PHONE or READ_PHONE_NUMBERS, and remove them with tools:node="remove".
Add NSCalendarsUsageDescription to Info.plist; device_calendar_plus needs it on every iOS version. If the participant denied calendar access, the measure reports an error instead of calendar data. Access can be turned on again in Settings → Privacy & Security → Calendars.
Next step
Quickstart
Build an app that collects calls, messages and calendar events.