If your app has ever offered “Save to contacts”, there is a good chance it declares WRITE_CONTACTS, shows a permission dialog, and then writes rows into ContactsContract with a ContentResolver. That pattern is on its way out. Android is separating "my app needs to save one contact" from "my app manages the whole address book", and only the second case keeps a permission.
This post walks through what is changing, the replacement APIs, how to write the UX so users don’t bounce, how to degrade on older devices, and how to test it. The code is Kotlin and leans on the Activity Result APIs rather than startActivityForResult. Imports are omitted from the snippets for brevity.
The timeline below comes from Android’s own announcement. Exact API levels for the “next release” were still being finalized when I wrote this, so check the Android Developers Blog post and the
Manifest.permissionreference before you pin a number in your build.
1. What is changing and when
The headline: apps that target the upcoming Android release will no longer be able to write contacts directly just because they hold WRITE_CONTACTS. Writes through the provider will fail with a SecurityException or a permission denial. In the same release, the three standard contact intents (ACTION_INSERT, ACTION_EDIT, ACTION_INSERT_OR_EDIT) become consistent across devices and need no permission.
Two other pieces matter:
- Contact Picker. Since Android 17, the system offers a picker for letting the user choose contacts you may read, with no permission.
-
MANAGE_CONTACTS. Appearing with Android 17 QPR2, this is a special app access for apps that legitimately manage the address book at scale (think dialers, contact managers, sync tools). It is not a drop-in replacement for the old runtime permission, and Google Play policy is expected to require a declaration for it.
Notice what is gated by what. The write restriction is tied to your targetSdk, not just the device version. An app that targets the old level keeps today's behavior on a new device for a while. That is a trap in disguise: the day you bump targetSdk for an unrelated reason, a contact-saving feature that tested fine for months can start throwing. Treat the target bump as a migration event for contacts.
A real failure mode: the “invisible” crash
A typical direct-write helper looks like this:
// The pattern that breaks when you raise targetSdk. // It is also blocking Binder + disk I/O, so it must never run on the main thread. fun saveContactDirect(resolver: ContentResolver, name: String, phone: String) { val ops = arrayListOf( ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI) .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null) .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null) .build(), ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE) .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name) .build(), ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE) .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phone) .build() ) resolver.applyBatch(ContactsContract.AUTHORITY, ops) // SecurityException on the new target } The crash is not in a screen you changed. It is in a helper someone wrote years ago, behind a button that few testers press. Search your codebase for ContactsContract.AUTHORITY, RawContacts.CONTENT_URI and applyBatch now, before the target bump lands.
2. System-mediated contact-editing APIs
The new mental model: your app proposes, the system editor disposes. You describe a contact; the user’s contacts app shows it; the user confirms. You never touch the provider.
The comparison between the two approaches is worth seeing at a glance:
A small, testable launcher
Keep intent construction in a pure function and the launching in a thin wrapper. That split pays off in testing (section 5).
data class ContactDraft( val name: String, val phone: String? = null, val email: String? = null, val company: String? = null, ) object ContactIntents { /** Always opens a blank-ish editor pre-filled with the draft. */ fun insert(draft: ContactDraft): Intent = Intent(ContactsContract.Intents.Insert.ACTION).apply { type = ContactsContract.RawContacts.CONTENT_TYPE putExtra(ContactsContract.Intents.Insert.NAME, draft.name) draft.phone?.let { putExtra(ContactsContract.Intents.Insert.PHONE, it) putExtra( ContactsContract.Intents.Insert.PHONE_TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE, ) } draft.email?.let { putExtra(ContactsContract.Intents.Insert.EMAIL, it) } draft.company?.let { putExtra(ContactsContract.Intents.Insert.COMPANY, it) } } /** Lets the system offer "update existing" when the number or email already matches. */ fun insertOrEdit(draft: ContactDraft): Intent = Intent(Intent.ACTION_INSERT_OR_EDIT).apply { type = ContactsContract.Contacts.CONTENT_ITEM_TYPE putExtra(ContactsContract.Intents.Insert.NAME, draft.name) draft.phone?.let { putExtra(ContactsContract.Intents.Insert.PHONE, it) } draft.email?.let { putExtra(ContactsContract.Intents.Insert.EMAIL, it) } } /** Edit a contact whose URI you already hold (for example from the picker). */ fun edit(contactUri: Uri): Intent = Intent(Intent.ACTION_EDIT).apply { // Set the MIME type explicitly; this is required for lookup URIs. setDataAndType(contactUri, ContactsContract.Contacts.CONTENT_ITEM_TYPE) } } Which one to default to? Prefer insertOrEdit for anything derived from data that can repeat (a customer, a chat counterpart, an order contact). Plain insert happily creates a duplicate every time the user taps the button twice.
Launching without crashing
sealed interface LaunchResult { data object Launched : LaunchResult data object NoContactsApp : LaunchResult } class ContactSaver(private val launch: (Intent) -> Unit) { fun save(draft: ContactDraft): LaunchResult = try { launch(ContactIntents.insertOrEdit(draft)) LaunchResult.Launched } catch (_: ActivityNotFoundException) { LaunchResult.NoContactsApp } } In a Compose screen, wire the lambda to an ActivityResultLauncher:
@Composable fun SaveContactButton(draft: ContactDraft, onOutcome: (SaveOutcome) -> Unit) { val currentOnOutcome by rememberUpdatedState(onOutcome) var editorOpen by rememberSaveable { mutableStateOf(false) } val launcher = rememberLauncherForActivityResult( ActivityResultContracts.StartActivityForResult() ) { result -> editorOpen = false // Treat as a hint only. See the failure mode below. currentOnOutcome( if (result.resultCode == Activity.RESULT_OK) SaveOutcome.LikelySaved else SaveOutcome.Unknown ) } val saver = remember(launcher) { ContactSaver { launcher.launch(it) } } Button( enabled = !editorOpen, // blocks double taps and the duplicate contacts they create onClick = { editorOpen = true if (saver.save(draft) is LaunchResult.NoContactsApp) { editorOpen = false currentOnOutcome(SaveOutcome.NoEditor) } }, ) { Text("Save to contacts") } } enum class SaveOutcome { LikelySaved, Unknown, NoEditor } Why try/catch instead of resolveActivity? On Android 11 and later, package visibility filtering can make resolveActivity return null for an intent that would actually launch, unless you add a matching <queries> entry. Catching ActivityNotFoundException is simpler and cannot disagree with reality.
Real-world failure modes
- The result code lies. Contacts apps from different vendors return
RESULT_OKorRESULT_CANCELEDinconsistently after a successful save, and many return no useful data. Without read access you cannot verify. Design the UI so an uncertain outcome is fine: a neutral message such as "Contact editor closed" beats a green "Saved!" you cannot prove. - Extras are suggestions. Vendor editors may drop fields (company, notes) or reformat phone numbers. Never build flows that assume every field arrives.
- Multiple default accounts. The editor may default to a Google account, a device-only account, or whatever the user last picked. You can hint, but you cannot force.
- Back stack surprises. Launching from a bottom sheet or a transient dialog can lose state if the process is killed while the editor is in front. Persist the draft in a
SavedStateHandleso returning users do not find an empty form.
Many contacts at once
An intent saves one contact per launch. For import-style features you have three honest options:
- A per-contact queue. Show “Save 3 of 12”, launch the editor for each one, and let the user skip. Slow, but fully permissionless and easy to reason about.
- A vCard handoff. Generate one
.vcffile in your cache, expose it through aFileProvider, and open it withACTION_VIEWso the user's contacts app can import the lot. Treat this as best effort: how a device handlestext/x-vcardis not covered by the standardized contact intents. Some devices have no vCard importer or route the file to a browser or share sheet, so handleActivityNotFoundExceptionand offer a share fallback.
fun vcardIntent(context: Context, file: File): Intent { // The authority must match the <provider> declared in your manifest exactly. val uri = FileProvider.getUriForFile(context, "${context.packageName}.fileprovider", file) return Intent(Intent.ACTION_VIEW).apply { setDataAndType(uri, "text/x-vcard") clipData = ClipData.newRawUri("contacts", uri) // helps grant propagation on older OEM builds addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) } } <provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> </provider> -
MANAGE_CONTACTS. Only if your product genuinely manages contacts. Expect store review to ask why.
3. UX copy and onboarding that doesn’t lose users
The old flow had a famous leak. A user tapped “Save”, met a system dialog asking for broad contact access, and a measurable share said no, even though they only wanted to save one number. The new flow removes that dialog entirely. Your job is to make sure the system editor does not feel like a detour.
Principles that hold up in practice
Name the outcome, not the mechanism. “Allow access to contacts?” is a security question. “Save Priya to your contacts” is a task.
Warn about the screen change, once. Users who expect a one-tap save are momentarily confused by a full editor. A single line under the button (“You’ll review it in your Contacts app”) removes most of that.
Never claim success you cannot verify. From section 2, the result code is unreliable. Use wording that matches your confidence.
Concrete rewrites:
- Button. Replace “Grant contact access” with “Save to contacts”.
- Before launch. Add a single line: “You’ll review this in your Contacts app.”
- After return, unsure. Replace “Saved!” with “Contact editor closed. Not saved? Try again.”
- No editor installed. Replace “Error” with “No contacts app found. Copy the number instead.”
Offer an escape hatch. For NoContactsApp, put a copy-to-clipboard action right in the snackbar. Dead ends are where users leave.
Remove the old rationale screen, but keep your read path honest. If you still request READ_CONTACTS for something else (say, matching friends), keep that request tied to that feature and its copy. Do not let a stale "we need contacts to save contacts" string survive in your resources.
Failure modes to watch
- Duplicate contacts from repeated taps. Debounce the button and prefer
insertOrEdit. - Stale permission strings and store disclosures. Dropping
WRITE_CONTACTSshould also update your privacy and data-safety disclosures. Check the policy text with whoever owns compliance rather than assuming. - Analytics that count a launch as a save. Rename the event to
contact_editor_opened; if you want a conversion number, derive it from something you can verify.
4. Graceful degradation on older API levels
The pleasant surprise: the intent actions have existed since the earliest Android versions, so the permissionless path is available on every device you are likely to support. “Available” is not “identical”, though. Before the standardization, vendor editors handled ACTION_INSERT_OR_EDIT and extras such as the target account inconsistently, and some stripped-down devices have no contacts app at all. You do not need two code paths for "old" and "new"; you need one path, tolerance for variation, and a few optional embellishments.
object ContactCapabilities { /** * Photo prefill is an editor-side feature of the next release, so it follows the device OS, * not your targetSdk. Stays disabled until you set the real level from Build.VERSION_CODES. */ fun supportsPhotoPrefill(): Boolean = Build.VERSION.SDK_INT >= NEXT_RELEASE_SDK // TODO: replace with the Build.VERSION_CODES constant once the release is final. private const val NEXT_RELEASE_SDK = Int.MAX_VALUE } Guidelines:
- One launcher, optional extras. Add new-release extras (such as the photo prefill) behind an SDK check and treat them as bonuses. An older editor ignoring an unknown extra is fine; building UI that depends on it is not.
- Retire the direct path on purpose. If you must keep a direct-write branch while some users sit on an old
targetSdkbuild, gate it on both the permission being granted and the platform behavior, and put a removal date on it. A branch that "might still be needed" is how aSecurityExceptionships. - Don’t fork on OEM. Vendor contact apps differ. Handle differences by tolerating missing fields, not by sniffing
Build.MANUFACTURER. - Keep a no-handler fallback. Some stripped-down or enterprise-managed devices ship without a contacts editor. The
NoContactsAppbranch is real, not theoretical. - Bulk features degrade to the queue or vCard. Those work on every version.
5. Testing across versions
Contact flows are a classic place where “works on my Pixel” hides three bugs. Here is a layered plan.
Unit tests: intent construction
Because ContactIntents is pure, you can assert on it without a device. With Robolectric (so Intent is real):
@RunWith(AndroidJUnit4::class) class ContactIntentsTest { @Test fun insertOrEdit_carriesNameAndPhone() { val intent = ContactIntents.insertOrEdit(ContactDraft(name = "Priya Raman", phone = "+91 98400 12345")) assertEquals(Intent.ACTION_INSERT_OR_EDIT, intent.action) assertEquals(ContactsContract.Contacts.CONTENT_ITEM_TYPE, intent.type) assertEquals("Priya Raman", intent.getStringExtra(ContactsContract.Intents.Insert.NAME)) assertEquals("+91 98400 12345", intent.getStringExtra(ContactsContract.Intents.Insert.PHONE)) } } Unit tests: the no-handler path
The injected launch lambda makes this trivial:
@Test fun save_returnsNoContactsApp_whenNothingHandlesTheIntent() { val saver = ContactSaver { throw ActivityNotFoundException() } assertEquals(LaunchResult.NoContactsApp, saver.save(ContactDraft(name = "Test"))) } Instrumented tests: stub the editor
You do not want a UI test to drive a vendor’s contacts app. Use Espresso-Intents to intercept the launch and to simulate outcomes:
@get:Rule val compose = createAndroidComposeRule<MainActivity>() @Before fun setUp() = Intents.init() @After fun tearDown() = Intents.release() @Test fun tappingSave_launchesEditor_andShowsNeutralMessageOnCancel() { intending(hasAction(Intent.ACTION_INSERT_OR_EDIT)) .respondWith(Instrumentation.ActivityResult(Activity.RESULT_CANCELED, null)) compose.onNodeWithText("Save to contacts").performClick() intended(allOf(hasAction(Intent.ACTION_INSERT_OR_EDIT), hasExtraWithKey(ContactsContract.Intents.Insert.NAME))) compose.onNodeWithText("Contact editor closed", substring = true).assertIsDisplayed() } If your editor launch can fire during onCreate, register the stubs before the activity starts (for example with ActivityScenario and Intents.init() ahead of launch) because this rule launches the activity first.
Note the assertion: after a cancel result, the UI shows neutral wording, not “saved” and not “failed”. That encodes the lesson from section 2 in a test.
The version matrix
- Emulators. Run the instrumented suite on a Gradle Managed Device matrix covering your
minSdk, a mid-range level, the latest stable release, and the preview image for the next release. Keep the preview run non-blocking until the platform stabilizes. - Two builds of the same app. Test once with your current
targetSdkand once with the new one on the same next-release device image; the matrix above has separate columns for exactly this reason. The failure you are hunting only appears in the second combination. - Android’s app compatibility tools. The platform’s app compatibility framework lets you toggle target-gated behavior changes per app on supported debuggable or preview builds (Developer Options or
adb shell am compat), which is the quickest way to flip the new write behavior on and off without changingtargetSdk. - Real devices from at least two vendors. Emulators ship Google’s contacts app. Try a Samsung-style and a stock-style editor by hand for field-dropping and account-default behavior, or use a device farm.
- Lint and grep gates in CI. Fail the build if
ContactsContract.AUTHORITYorWRITE_CONTACTSreappears outside an allow-listed module. Cheap, and it catches regressions from copied snippets.
A short migration checklist
- Inventory every use of
WRITE_CONTACTSandapplyBatchagainst the contacts authority. - Replace single-contact writes with
insertOrEditthrough a testable launcher. - Rewrite copy; delete permission rationale for writing.
- Decide the bulk story: queue, vCard, or
MANAGE_CONTACTSwith a clear justification. - Update store disclosures with your compliance owner.
- Add the CI gate, then bump
targetSdkon a branch and run the matrix.
🔚 Closing thoughts
Losing WRITE_CONTACTS for ordinary apps is mostly good news: fewer scary dialogs, fewer data-access liabilities, and one code path that works from your oldest supported device to the newest. The cost is humility. You no longer control the save, so you cannot know for sure it happened. Build the flow, the copy, and the tests around that uncertainty and the migration is boring in the best way.
📘 Master Your Next Technical Interview
Since Java is the foundation of Android development, mastering DSA is essential. I highly recommend “Mastering Data Structures & Algorithms in Java”. It’s a focused roadmap covering 100+ coding challenges to help you ace your technical rounds.
- E-book: Available on Google Play
- Kindle Edition: Available on Amazon
- Topmate: Available on Topmate
- Also available in Paperback & Hardcover.










