@capacitor/contacts 1.1.0-dev.1 → 2.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
13
  s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '15.0'
14
+ s.ios.deployment_target = '16.0'
15
15
  s.frameworks = 'Contacts', 'ContactsUI'
16
16
  s.dependency 'Capacitor'
17
17
  s.swift_version = '5.1'
package/Package.swift CHANGED
@@ -3,21 +3,20 @@ import PackageDescription
3
3
 
4
4
  let package = Package(
5
5
  name: "CapacitorContacts",
6
- platforms: [.iOS(.v15)],
6
+ platforms: [.iOS(.v16)],
7
7
  products: [
8
8
  .library(
9
9
  name: "CapacitorContacts",
10
10
  targets: ["ContactsPlugin"])
11
11
  ],
12
12
  dependencies: [
13
- .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
13
+ .package(url: "https://github.com/ionic-team/capacitor.git", from: "9.0.0-beta.0")
14
14
  ],
15
15
  targets: [
16
16
  .target(
17
17
  name: "ContactsPlugin",
18
18
  dependencies: [
19
- .product(name: "Capacitor", package: "capacitor-swift-pm"),
20
- .product(name: "Cordova", package: "capacitor-swift-pm")
19
+ .product(name: "Capacitor", package: "capacitor")
21
20
  ],
22
21
  path: "ios/Sources/ContactsPlugin"),
23
22
  .testTarget(
package/README.md CHANGED
@@ -52,41 +52,13 @@ The plugin declares `READ_CONTACTS` and `WRITE_CONTACTS` in its own
52
52
  manifest; Gradle manifest merging adds them to your app automatically. Each
53
53
  method requests the runtime permission it needs the first time it runs;
54
54
  read for `find`/`pickContact`, read + write for `save`/`remove`.
55
- The `pickContactField` method needs no permission: it opens the contacts app on a single
56
- data kind (phone, email or address), and the app grants temporary read access
57
- to just the row the user selects.
58
-
59
- :::warning[Google Play Requirements]
60
-
61
- The `pickContactField` method exists mainly to adhere to Google Play's restrictions for the Contacts Permission. This only applies to apps using Capacitor 9 or higher. You should evaluate whether `pickContactField` is enough for your app's use cases. If not, you may need to submit a Play Console declaration. For more information refer to [Google Play's page](https://support.google.com/googleplay/android-developer/answer/16909972?sjid=14458661934730177096-EU#contacts-permissions).
62
-
63
- :::
64
-
65
- If your app only uses `pickContactField`, you can keep the contacts
66
- permissions out of your app by removing them from the merged manifest in your
67
- app's `AndroidManifest.xml`:
68
-
69
- ```xml
70
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
71
- xmlns:tools="http://schemas.android.com/tools">
72
-
73
- <uses-permission android:name="android.permission.READ_CONTACTS" tools:node="remove" />
74
- <uses-permission android:name="android.permission.WRITE_CONTACTS" tools:node="remove" />
75
- </manifest>
76
- ```
77
-
78
- The other methods then reject with `OS-PLUG-CONT-0021`, because the
79
- permissions they need are not declared.
80
55
 
81
56
  ## Permission model
82
57
 
83
58
  This plugin intentionally exposes **no** `checkPermissions()` /
84
59
  `requestPermissions()` methods: permissions are requested implicitly by each
85
60
  method, matching the legacy `cordova-plugin-contacts` behavior. A call
86
- rejects with `OS-PLUG-CONT-0020` when the user denies access. `pickContactField`
87
- needs no permission. On Android, the other methods reject with
88
- `OS-PLUG-CONT-0021` when the permissions they need are not declared in the
89
- app's manifest.
61
+ rejects with `OS-PLUG-CONT-0020` when the user denies access.
90
62
 
91
63
  ## Errors
92
64
 
@@ -102,7 +74,6 @@ Every rejection carries a structured code + message:
102
74
  | `OS-PLUG-CONT-0005` | Not supported |
103
75
  | `OS-PLUG-CONT-0006` | Operation cancelled (picker closed) |
104
76
  | `OS-PLUG-CONT-0020` | Permission denied |
105
- | `OS-PLUG-CONT-0021` | Required permission not declared in the Android manifest |
106
77
 
107
78
  ## Usage
108
79
 
@@ -129,12 +100,9 @@ const saved = await Contacts.save({
129
100
  // Update it (id present -> update)
130
101
  await Contacts.save({ contact: { ...saved, nickname: 'Countess' } });
131
102
 
132
- // Pick a contact with the native picker; needs contacts permission on Android
103
+ // Pick a contact with the native picker
133
104
  const picked = await Contacts.pickContact();
134
105
 
135
- // Pick a single phone number, email or address; needs no contacts permission on both platforms
136
- const { value, type, displayName } = await Contacts.pickContactField({ field: 'phone' });
137
-
138
106
  // Remove it by id
139
107
  await Contacts.remove({ id: saved.id! });
140
108
  ```
@@ -147,7 +115,6 @@ await Contacts.remove({ id: saved.id! });
147
115
  * [`save(...)`](#save)
148
116
  * [`remove(...)`](#remove)
149
117
  * [`pickContact()`](#pickcontact)
150
- * [`pickContactField(...)`](#pickcontactfield)
151
118
  * [Interfaces](#interfaces)
152
119
  * [Type Aliases](#type-aliases)
153
120
 
@@ -252,31 +219,6 @@ contact's details.
252
219
  --------------------
253
220
 
254
221
 
255
- ### pickContactField(...)
256
-
257
- ```typescript
258
- pickContactField(options: PickContactFieldOptions) => Promise<PickedContactField>
259
- ```
260
-
261
- Launches the native contact picker UI, showing only the requested kind of
262
- information, and resolves with the single value the user selects (not a
263
- full contact). Rejects with `OS-PLUG-CONT-0006` if the user cancels.
264
-
265
- Needs no contacts permission on either platform, which lets Android apps
266
- omit READ_CONTACTS from their manifest. Only one data kind can be picked
267
- per call.
268
-
269
- | Param | Type |
270
- | ------------- | --------------------------------------------------------------------------- |
271
- | **`options`** | <code><a href="#pickcontactfieldoptions">PickContactFieldOptions</a></code> |
272
-
273
- **Returns:** <code>Promise&lt;<a href="#pickedcontactfield">PickedContactField</a>&gt;</code>
274
-
275
- **Since:** 1.1.0
276
-
277
- --------------------
278
-
279
-
280
222
  ### Interfaces
281
223
 
282
224
 
@@ -401,43 +343,6 @@ Options accepted by {@link ContactsPlugin.remove}.
401
343
  | **`id`** | <code>string</code> | The native id of the contact to remove. | 1.0.0 |
402
344
 
403
345
 
404
- #### PickedContactField
405
-
406
- The value the user picked with {@link ContactsPlugin.pickContactField}. This is
407
- not a full contact: it holds only the picked value, its label and the
408
- contact's display name.
409
-
410
- | Prop | Type | Description | Since |
411
- | ----------------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | ----- |
412
- | **`field`** | <code>'phone' \| 'email' \| 'address'</code> | The kind of value that was picked, as requested. | 1.1.0 |
413
- | **`value`** | <code>string</code> | The picked phone number, email address, or postal address formatted for display, depending on `field`. | 1.1.0 |
414
- | **`type`** | <code>string</code> | The label of the picked value, e.g. `mobile`, `home`, `work`. | 1.1.0 |
415
- | **`displayName`** | <code>string</code> | The display name of the contact the value belongs to, when available. | 1.1.0 |
416
- | **`address`** | <code><a href="#pickedcontactaddress">PickedContactAddress</a></code> | The parts of the postal address. Only present when `field` is `address`. | 1.1.0 |
417
-
418
-
419
- #### PickedContactAddress
420
-
421
- The parts of a postal address returned by {@link ContactsPlugin.pickContactField}.
422
-
423
- | Prop | Type | Description | Since |
424
- | ------------------- | ------------------- | --------------------- | ----- |
425
- | **`streetAddress`** | <code>string</code> | The street address. | 1.1.0 |
426
- | **`locality`** | <code>string</code> | The city or locality. | 1.1.0 |
427
- | **`region`** | <code>string</code> | The state or region. | 1.1.0 |
428
- | **`postalCode`** | <code>string</code> | The postal code. | 1.1.0 |
429
- | **`country`** | <code>string</code> | The country. | 1.1.0 |
430
-
431
-
432
- #### PickContactFieldOptions
433
-
434
- Options accepted by {@link ContactsPlugin.pickContactField}.
435
-
436
- | Prop | Type | Description | Since |
437
- | ----------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------- | ----- |
438
- | **`field`** | <code>'phone' \| 'email' \| 'address'</code> | The single kind of contact information to pick. Any other value rejects with `OS-PLUG-CONT-0001`. | 1.1.0 |
439
-
440
-
441
346
  ### Type Aliases
442
347
 
443
348
 
@@ -1,14 +1,13 @@
1
1
  ext {
2
2
  capacitorVersion = System.getenv('CAPACITOR_VERSION')
3
3
  junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
4
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.8.0'
5
5
  androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
6
6
  androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
7
- androidxCoreKTXVersion = project.hasProperty('androidxCoreKTXVersion') ? rootProject.ext.androidxCoreKTXVersion : '1.17.0'
7
+ androidxCoreVersion = project.hasProperty('androidxCoreVersion') ? rootProject.ext.androidxCoreVersion : '1.19.1'
8
8
  }
9
9
 
10
10
  buildscript {
11
- ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '2.2.20'
12
11
  repositories {
13
12
  google()
14
13
  mavenCentral()
@@ -17,8 +16,7 @@ buildscript {
17
16
  }
18
17
  }
19
18
  dependencies {
20
- classpath 'com.android.tools.build:gradle:8.13.0'
21
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
19
+ classpath 'com.android.tools.build:gradle:9.4.1'
22
20
  if (System.getenv("CAP_PLUGIN_PUBLISH") == "true") {
23
21
  classpath 'io.github.gradle-nexus:publish-plugin:1.3.0'
24
22
  }
@@ -27,9 +25,6 @@ buildscript {
27
25
 
28
26
 
29
27
  apply plugin: 'com.android.library'
30
- if (project.extensions.findByName('kotlin') == null) {
31
- apply plugin: 'kotlin-android'
32
- }
33
28
 
34
29
  if (System.getenv("CAP_PLUGIN_PUBLISH") == "true") {
35
30
  apply plugin: 'io.github.gradle-nexus.publish-plugin'
@@ -39,10 +34,10 @@ if (System.getenv("CAP_PLUGIN_PUBLISH") == "true") {
39
34
 
40
35
  android {
41
36
  namespace = "com.capacitorjs.plugins.contacts"
42
- compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
37
+ compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 37
43
38
  defaultConfig {
44
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
45
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
39
+ consumerProguardFiles "proguard-rules.pro"
40
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 26
46
41
  versionCode 1
47
42
  versionName "1.0"
48
43
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -83,7 +78,7 @@ dependencies {
83
78
  implementation project(':capacitor-android')
84
79
  }
85
80
  implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
86
- implementation "androidx.core:core-ktx:$androidxCoreKTXVersion"
81
+ implementation "androidx.core:core:$androidxCoreVersion"
87
82
  testImplementation "junit:junit:$junitVersion"
88
83
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
89
84
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
@@ -0,0 +1,21 @@
1
+ # Add project specific ProGuard rules here.
2
+ # You can control the set of applied configuration files using the
3
+ # proguardFiles setting in build.gradle.
4
+ #
5
+ # For more details, see
6
+ # http://developer.android.com/guide/developing/tools/proguard.html
7
+
8
+ # If your project uses WebView with JS, uncomment the following
9
+ # and specify the fully qualified class name to the JavaScript interface
10
+ # class:
11
+ #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12
+ # public *;
13
+ #}
14
+
15
+ # Uncomment this to preserve the line number information for
16
+ # debugging stack traces.
17
+ #-keepattributes SourceFile,LineNumberTable
18
+
19
+ # If you keep the line number information, uncomment this to
20
+ # hide the original source file name.
21
+ #-renamesourcefileattribute SourceFile
@@ -220,71 +220,6 @@ class Contacts(private val context: Context) {
220
220
  return null
221
221
  }
222
222
 
223
- /**
224
- * Reads the single data row returned by an `ACTION_PICK` on [kind]'s
225
- * data-kind URI into a `pickContactField` result: the picked `value` and
226
- * its `type` label, plus the contact's `displayName` when available.
227
- * Picking a specific data-kind URI instead of the generic
228
- * `Contacts.CONTENT_URI` makes the device's contacts app delegate
229
- * temporary read permission on just that row, so no READ_CONTACTS
230
- * permission is needed.
231
- *
232
- * @param kind the data kind that was requested from the picker.
233
- * @param pickedUri the URI of the row the contacts app returned.
234
- * @return the result with `field`, `value`, `type`, `displayName` (when
235
- * known) and, for addresses, `address`; null if the row is gone or holds
236
- * no value.
237
- * @throws SecurityException if the provider refuses to read the row.
238
- */
239
- fun readPickedField(kind: ContactPickableField, pickedUri: Uri): JSObject? {
240
- val projection = arrayOf(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY) + when (kind) {
241
- ContactPickableField.PHONE -> arrayOf(Phone.NUMBER, Phone.TYPE, Phone.LABEL)
242
- ContactPickableField.EMAIL -> arrayOf(Email.ADDRESS, Email.TYPE, Email.LABEL)
243
- ContactPickableField.ADDRESS -> arrayOf(
244
- StructuredPostal.FORMATTED_ADDRESS, StructuredPostal.STREET, StructuredPostal.CITY,
245
- StructuredPostal.REGION, StructuredPostal.POSTCODE, StructuredPostal.COUNTRY,
246
- StructuredPostal.TYPE, StructuredPostal.LABEL
247
- )
248
- }
249
-
250
- context.contentResolver.query(pickedUri, projection, null, null, null)?.use { cursor ->
251
- if (!cursor.moveToFirst()) return null
252
- fun str(name: String): String? {
253
- val i = cursor.getColumnIndex(name)
254
- return if (i >= 0) cursor.getString(i) else null
255
- }
256
- fun int(name: String): Int {
257
- val i = cursor.getColumnIndex(name)
258
- return if (i >= 0) cursor.getInt(i) else -1
259
- }
260
-
261
- val result = JSObject()
262
- result.put("field", kind.key)
263
- when (kind) {
264
- ContactPickableField.PHONE -> {
265
- result.put("value", str(Phone.NUMBER) ?: return null)
266
- result.put("type", phoneLabel(int(Phone.TYPE), str(Phone.LABEL)))
267
- }
268
-
269
- ContactPickableField.EMAIL -> {
270
- result.put("value", str(Email.ADDRESS) ?: return null)
271
- result.put("type", emailLabel(int(Email.TYPE), str(Email.LABEL)))
272
- }
273
-
274
- ContactPickableField.ADDRESS -> {
275
- result.put("value", str(StructuredPostal.FORMATTED_ADDRESS) ?: return null)
276
- result.put("type", addressLabel(int(StructuredPostal.TYPE), str(StructuredPostal.LABEL)))
277
- val address = JSObject()
278
- putAddressParts(address, ::str)
279
- result.put("address", address)
280
- }
281
- }
282
- str(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY)?.let { result.put("displayName", it) }
283
- return result
284
- }
285
- return null
286
- }
287
-
288
223
  private fun wants(field: String, desiredFields: Set<String>): Boolean =
289
224
  desiredFields.isEmpty() || desiredFields.contains(field)
290
225
 
@@ -372,7 +307,11 @@ class Contacts(private val context: Context) {
372
307
  address.put("pref", pref)
373
308
  address.put("type", addressLabel(int(StructuredPostal.TYPE), str(StructuredPostal.LABEL)))
374
309
  address.put("formatted", str(StructuredPostal.FORMATTED_ADDRESS))
375
- putAddressParts(address, ::str)
310
+ address.put("streetAddress", str(StructuredPostal.STREET))
311
+ address.put("locality", str(StructuredPostal.CITY))
312
+ address.put("region", str(StructuredPostal.REGION))
313
+ address.put("postalCode", str(StructuredPostal.POSTCODE))
314
+ address.put("country", str(StructuredPostal.COUNTRY))
376
315
  addresses.put(address)
377
316
  }
378
317
 
@@ -462,21 +401,6 @@ class Contacts(private val context: Context) {
462
401
  return contact
463
402
  }
464
403
 
465
- /**
466
- * Puts the postal parts of a StructuredPostal row into [address].
467
- *
468
- * @param address the object to fill with `streetAddress`, `locality`,
469
- * `region`, `postalCode` and `country`.
470
- * @param str reads a column of the current row, null when it has no value.
471
- */
472
- private fun putAddressParts(address: JSObject, str: (String) -> String?) {
473
- address.put("streetAddress", str(StructuredPostal.STREET))
474
- address.put("locality", str(StructuredPostal.CITY))
475
- address.put("region", str(StructuredPostal.REGION))
476
- address.put("postalCode", str(StructuredPostal.POSTCODE))
477
- address.put("country", str(StructuredPostal.COUNTRY))
478
- }
479
-
480
404
  private fun field(id: String?, value: String?, type: String?, pref: Boolean): JSObject {
481
405
  val f = JSObject()
482
406
  if (id != null) f.put("id", id)
@@ -13,8 +13,7 @@ enum class ContactsError(val code: String, val message: String) {
13
13
  IO_ERROR("OS-PLUG-CONT-0004", "An I/O error occurred while accessing contacts."),
14
14
  NOT_SUPPORTED("OS-PLUG-CONT-0005", "The operation is not supported on this device."),
15
15
  OPERATION_CANCELLED("OS-PLUG-CONT-0006", "The operation was cancelled."),
16
- PERMISSION_DENIED("OS-PLUG-CONT-0020", "Contacts permission was denied."),
17
- PERMISSION_NOT_DECLARED("OS-PLUG-CONT-0021", "A required contacts permission is not declared in the app manifest.")
16
+ PERMISSION_DENIED("OS-PLUG-CONT-0020", "Contacts permission was denied.")
18
17
  }
19
18
 
20
19
  /**
@@ -3,7 +3,6 @@ package com.capacitorjs.plugins.contacts
3
3
  import android.Manifest
4
4
  import android.app.Activity
5
5
  import android.content.Intent
6
- import android.net.Uri
7
6
  import android.provider.ContactsContract
8
7
  import com.getcapacitor.JSObject
9
8
  import com.getcapacitor.PermissionState
@@ -24,14 +23,7 @@ import java.util.concurrent.Executors
24
23
  * Permission model is **implicit**: there are no `checkPermissions` /
25
24
  * `requestPermissions` methods. Each method ensures the permission it needs
26
25
  * before touching the provider: read for `find`/`pickContact`, read+write
27
- * for `save`/`remove`. `pickContactField` is the exception and needs no
28
- * permission: it runs `ACTION_PICK` on a single data-kind URI (phone, email
29
- * or address) instead of the generic `Contacts.CONTENT_URI`, which makes the
30
- * device's contacts app delegate temporary read permission on just the
31
- * selected row. On Android 17+ the system routes the same intent to the new
32
- * Contacts Picker, so no API-level branching is needed. The tradeoff is that
33
- * only one data kind can be picked per call. All provider work runs off the
34
- * main thread.
26
+ * for `save`/`remove`. All provider work runs off the main thread.
35
27
  */
36
28
  @CapacitorPlugin(
37
29
  name = "Contacts",
@@ -183,55 +175,14 @@ class ContactsPlugin : Plugin() {
183
175
  private var pickInProgress = false
184
176
 
185
177
  private fun runPickContact(call: PluginCall) {
186
- startPicker(call, Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI), "pickContactResult")
187
- }
188
-
189
- @ActivityCallback
190
- private fun pickContactResult(call: PluginCall?, result: androidx.activity.result.ActivityResult) {
191
- handlePickResult(call, result) { uri -> uri.lastPathSegment?.let { implementation.getContactById(it) } }
192
- }
193
-
194
- // ------------------------------------------------------------------
195
- // pickContactField
196
- // ------------------------------------------------------------------
197
-
198
- @PluginMethod
199
- fun pickContactField(call: PluginCall) {
200
- val field = ContactPickableField.fromKey(call.getString("field"))
201
- if (field == null) {
202
- reject(call, ContactsError.INVALID_ARGUMENT)
203
- return
204
- }
205
- startPicker(call, Intent(Intent.ACTION_PICK, field.contentUri), "pickContactFieldResult")
206
- }
207
-
208
- @ActivityCallback
209
- private fun pickContactFieldResult(call: PluginCall?, result: androidx.activity.result.ActivityResult) {
210
- val field = ContactPickableField.fromKey(call?.getString("field"))
211
- handlePickResult(call, result) { uri -> field?.let { implementation.readPickedField(it, uri) } }
212
- }
213
-
214
- // ------------------------------------------------------------------
215
- // Shared picker flow
216
- // ------------------------------------------------------------------
217
-
218
- /**
219
- * Launches [intent] for [call], rejecting with `PENDING_OPERATION` if
220
- * another picker is on screen and with `NOT_SUPPORTED` if no activity can
221
- * handle [intent].
222
- *
223
- * @param call the call to resolve once the picker returns.
224
- * @param intent the `ACTION_PICK` intent to launch.
225
- * @param callbackName name of the `@ActivityCallback` that receives the result.
226
- */
227
- private fun startPicker(call: PluginCall, intent: Intent, callbackName: String) {
228
178
  if (pickInProgress) {
229
179
  reject(call, ContactsError.PENDING_OPERATION)
230
180
  return
231
181
  }
232
182
  pickInProgress = true
183
+ val intent = Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI)
233
184
  try {
234
- startActivityForResult(call, intent, callbackName)
185
+ startActivityForResult(call, intent, "pickContactResult")
235
186
  } catch (e: Exception) {
236
187
  // No contacts app / picker activity on this device.
237
188
  pickInProgress = false
@@ -239,35 +190,22 @@ class ContactsPlugin : Plugin() {
239
190
  }
240
191
  }
241
192
 
242
- /**
243
- * Resolves [call] with what [read] returns for the picked URI, or rejects
244
- * on cancel or failure. [read] runs on the executor, so it may query the
245
- * provider.
246
- *
247
- * @param call the call that started the picker, null if it was lost.
248
- * @param result the picker's activity result.
249
- * @param read turns the picked URI into the result, null if it holds no data.
250
- */
251
- private fun handlePickResult(
252
- call: PluginCall?,
253
- result: androidx.activity.result.ActivityResult,
254
- read: (Uri) -> JSObject?
255
- ) {
193
+ @ActivityCallback
194
+ private fun pickContactResult(call: PluginCall?, result: androidx.activity.result.ActivityResult) {
256
195
  pickInProgress = false
257
196
  if (call == null) return
258
197
  when (result.resultCode) {
259
198
  Activity.RESULT_OK -> {
260
199
  val uri = result.data?.data
261
- if (uri == null) {
200
+ val contactId = uri?.lastPathSegment
201
+ if (contactId == null) {
262
202
  reject(call, ContactsError.UNKNOWN)
263
203
  return
264
204
  }
265
205
  executor.execute {
266
206
  try {
267
- val contact = read(uri)
207
+ val contact = implementation.getContactById(contactId)
268
208
  if (contact != null) call.resolve(contact) else reject(call, ContactsError.UNKNOWN)
269
- } catch (e: SecurityException) {
270
- reject(call, ContactsError.PERMISSION_DENIED, e)
271
209
  } catch (e: Exception) {
272
210
  reject(call, ContactsError.UNKNOWN, e)
273
211
  }
@@ -288,15 +226,8 @@ class ContactsPlugin : Plugin() {
288
226
  else -> READ
289
227
  }
290
228
 
291
- /**
292
- * Rejects with `PERMISSION_NOT_DECLARED` if the manifest lacks the method's permissions,
293
- * otherwise ensures its permission alias and dispatches the saved call.
294
- */
229
+ /** Ensures the method's permission alias, then dispatches the saved call. */
295
230
  private fun ensurePermission(call: PluginCall) {
296
- if (!isPermissionDeclared(aliasFor(call))) {
297
- reject(call, ContactsError.PERMISSION_NOT_DECLARED)
298
- return
299
- }
300
231
  if (getPermissionState(aliasFor(call)) == PermissionState.GRANTED) {
301
232
  dispatch(call)
302
233
  } else {