跪拜 Guibai
← All articles
Android

Android Kills Direct WRITE_CONTACTS: Migration Guide to Intent-Based Contact Editing

By 黄林晴 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Direct contacts manipulation will break for apps targeting the 2027 Android release, forcing a redesign of the write path. The replacement Intents shift user-visible behavior to the system editor, which changes UX and requires careful handling of result callbacks and permission grants.

Summary

Android has announced a two-phase plan to phase out direct contacts writes. For apps targeting the next Android version in 2027, requesting `WRITE_CONTACTS` alone will no longer allow direct insertion or modification of contacts. The first phase, in 2026's Android 17 QPR2, introduces the `MANAGE_CONTACTS` special access permission; the second phase, alongside the 2027 release, tightens direct write behavior and unifies contact Intent handling. Apps targeting older versions keep existing behavior, but device system version and target SDK must be evaluated separately.

For user-initiated actions like saving a business card or adding a phone number, the recommended path is now to launch the system's contact editor via Intents. `ACTION_INSERT` creates a new contact with pre-filled fields; `ACTION_INSERT_OR_EDIT` lets the user choose an existing contact or create a new one; `ACTION_EDIT` edits a known contact URI. These Intents do not require the `WRITE_CONTACTS` permission and shift the final save decision to the user, which changes the interaction flow: the app can no longer assume the write succeeded after calling `startActivity()`.

For background sync scenarios, such as two-way enterprise contact sync or bulk backup/restore, apps must evaluate the new special access permission `MANAGE_CONTACTS`. This permission must be granted through system settings, not the runtime permission dialog, and covers read, add, update, and delete. The article also covers account hints via `EXTRA_ACCOUNT`, photo pre-fill via the upcoming `EXTRA_PHOTO_URI` field, the need to pair URI grants with `ClipData`, and the pitfall of deleting avatar files too early. Code audits should search for `WRITE_CONTACTS`, `RawContacts.CONTENT_URI`, `Data.CONTENT_URI`, and `applyBatch`, then confirm each usage to separate queries from writes.

Takeaways
— WRITE_CONTACTS will no longer grant direct write access for apps targeting the 2027 Android version; the change is split into two stages starting with Android 17 QPR2 in 2026.
— The new special access permission MANAGE_CONTACTS is for background sync tasks and must be granted via system settings, not requestPermissions().
— For user-triggered saves, use ACTION_INSERT to create a new contact with pre-filled fields; the system editor handles the final save.
— When the target contact is unknown, use ACTION_INSERT_OR_EDIT to let the user pick an existing contact or create a new one.
— When the contact URI is known, use ACTION_EDIT to pre-fill additional data such as a phone number.
— After launching an Intent, startActivity() returning does not mean the contact was saved; the user may cancel or modify fields.
— For avatar pre-fill, the upcoming EXTRA_PHOTO_URI requires giving read permission via ClipData and FLAG_GRANT_READ_URI_PERMISSION; private files must be exposed through FileProvider first.
— Do not delete avatar files right after starting the editor; the editor may not have finished reading them.
— The EXTRA_ACCOUNT field for choosing a contact account has existed since API 23, not a new API in this change.
— The new editor ignores custom MIME rows; only standard ContactsContract.CommonDataKinds types are supported.
— Contact Intents have no delete action; ACTION_EDIT cannot be used to delete a contact.
— Use maxSdkVersion to keep the old WRITE_CONTACTS permission only on older devices, but the exact SDK level must match the compatibility implementation, not Android 17's API level.
— Audit code with rg for WRITE_CONTACTS, RawContacts.CONTENT_URI, Data.CONTENT_URI, and applyBatch, then verify each match is actually a write, not a query.
Conclusions

The deletion of WRITE_CONTACTS reflects a broader Android trend of moving sensitive user data operations behind system UI, trading app control for user consent and consistency.

The two-phase rollout means developers have a clear migration window, but the true breaking point is not the device's Android version but the target SDK, a distinction that often trips up teams.

The requirement to use ClipData alongside the photo URI is easy to miss; without it, the receiving editor cannot read the image even though the URI is present.

The line between user-initiated and background sync is the key architectural decision; apps that try to pass off background sync as user-initiated will likely face Play policy rejection.

Concepts & terms
WRITE_CONTACTS
A dangerous Android runtime permission that allows an app to write to the ContactsProvider. It is being deprecated for direct writes in favor of Intent-based editing or the special MANAGE_CONTACTS permission.
MANAGE_CONTACTS
A special app access permission for Android that grants broad read and write access to contacts, intended for background sync tasks. It must be enabled in system settings and is not shown as a runtime permission dialog.
ACTION_INSERT
An Android Intent action that opens the system's contact editor to create a new contact, pre-filling fields from Extras. The user confirms and saves the contact.
ACTION_INSERT_OR_EDIT
An Intent action that lets the user either select an existing contact or create a new one, with pre-filled fields passed along.
ACTION_EDIT
An Intent action that opens the system's editor for an existing contact, identified by a contact URI. It can pre-fill additional data.
RawContacts vs Contacts
RawContacts are per-account individual records, while Contacts are the aggregated view combining duplicate raw contacts. The two are distinct layers; URIs must point to the correct layer.
EXTRA_PHOTO_URI
A new Intent extra planned for Android 2027 to pass a photo URI for avatar pre-fill in the system contact editor. Requires the SDK containing the constant and proper URI permission grants.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗