react-native-contacts 7.0.8 → 8.0.0
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.
- package/android/build.gradle +28 -1
- package/android/src/main/java/com/rt2zz/reactnativecontacts/ContactsProvider.java +123 -129
- package/android/src/main/java/com/rt2zz/reactnativecontacts/ReactNativeContacts.java +32 -16
- package/android/src/newarch/com/rt2zz/reactnativecontacts/ContactsManager.java +1388 -0
- package/android/src/{main/java → oldarch}/com/rt2zz/reactnativecontacts/ContactsManager.java +100 -88
- package/index.d.ts +10 -10
- package/index.ts +113 -0
- package/ios/RCTContacts/RCTContacts.h +13 -1
- package/ios/RCTContacts/{RCTContacts.m → RCTContacts.mm} +519 -39
- package/package.json +19 -4
- package/react-native-contacts.podspec +27 -8
- package/src/NativeContacts.ts +27 -0
- package/type.ts +62 -0
- package/index.js +0 -2
package/android/src/{main/java → oldarch}/com/rt2zz/reactnativecontacts/ContactsManager.java
RENAMED
|
@@ -72,7 +72,7 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
|
-
* Introduced for iOS compatibility.
|
|
75
|
+
* Introduced for iOS compatibility. Same as getAll
|
|
76
76
|
*
|
|
77
77
|
* @param promise promise
|
|
78
78
|
*/
|
|
@@ -83,12 +83,13 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* Retrieves contacts.
|
|
86
|
-
* Uses raw URI when <code>rawUri</code> is <code>true</code>, makes assets copy
|
|
86
|
+
* Uses raw URI when <code>rawUri</code> is <code>true</code>, makes assets copy
|
|
87
|
+
* otherwise.
|
|
87
88
|
*/
|
|
88
89
|
private void getAllContacts(final Promise promise) {
|
|
89
|
-
AsyncTask<Void,Void,Void> myAsyncTask = new AsyncTask<Void,Void,Void>() {
|
|
90
|
+
AsyncTask<Void, Void, Void> myAsyncTask = new AsyncTask<Void, Void, Void>() {
|
|
90
91
|
@Override
|
|
91
|
-
protected Void doInBackground(final Void
|
|
92
|
+
protected Void doInBackground(final Void... params) {
|
|
92
93
|
Context context = getReactApplicationContext();
|
|
93
94
|
ContentResolver cr = context.getContentResolver();
|
|
94
95
|
|
|
@@ -103,9 +104,9 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
103
104
|
|
|
104
105
|
@ReactMethod
|
|
105
106
|
public void getCount(final Promise promise) {
|
|
106
|
-
AsyncTask<Void,Void,Void> myAsyncTask = new AsyncTask<Void,Void,Void>() {
|
|
107
|
+
AsyncTask<Void, Void, Void> myAsyncTask = new AsyncTask<Void, Void, Void>() {
|
|
107
108
|
@Override
|
|
108
|
-
protected Void doInBackground(final Void
|
|
109
|
+
protected Void doInBackground(final Void... params) {
|
|
109
110
|
Context context = getReactApplicationContext();
|
|
110
111
|
ContentResolver cr = context.getContentResolver();
|
|
111
112
|
|
|
@@ -126,15 +127,16 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
126
127
|
|
|
127
128
|
/**
|
|
128
129
|
* Retrieves contacts matching String.
|
|
129
|
-
* Uses raw URI when <code>rawUri</code> is <code>true</code>, makes assets copy
|
|
130
|
+
* Uses raw URI when <code>rawUri</code> is <code>true</code>, makes assets copy
|
|
131
|
+
* otherwise.
|
|
130
132
|
*
|
|
131
133
|
* @param searchString String to match
|
|
132
134
|
*/
|
|
133
135
|
@ReactMethod
|
|
134
136
|
public void getContactsMatchingString(final String searchString, final Promise promise) {
|
|
135
|
-
AsyncTask<Void,Void,Void> myAsyncTask = new AsyncTask<Void,Void,Void>() {
|
|
137
|
+
AsyncTask<Void, Void, Void> myAsyncTask = new AsyncTask<Void, Void, Void>() {
|
|
136
138
|
@Override
|
|
137
|
-
protected Void doInBackground(final Void
|
|
139
|
+
protected Void doInBackground(final Void... params) {
|
|
138
140
|
Context context = getReactApplicationContext();
|
|
139
141
|
ContentResolver cr = context.getContentResolver();
|
|
140
142
|
ContactsProvider contactsProvider = new ContactsProvider(cr);
|
|
@@ -149,15 +151,16 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
149
151
|
|
|
150
152
|
/**
|
|
151
153
|
* Retrieves contacts matching a phone number.
|
|
152
|
-
* Uses raw URI when <code>rawUri</code> is <code>true</code>, makes assets copy
|
|
154
|
+
* Uses raw URI when <code>rawUri</code> is <code>true</code>, makes assets copy
|
|
155
|
+
* otherwise.
|
|
153
156
|
*
|
|
154
157
|
* @param phoneNumber phone number to match
|
|
155
158
|
*/
|
|
156
159
|
@ReactMethod
|
|
157
160
|
public void getContactsByPhoneNumber(final String phoneNumber, final Promise promise) {
|
|
158
|
-
AsyncTask<Void,Void,Void> myAsyncTask = new AsyncTask<Void,Void,Void>() {
|
|
161
|
+
AsyncTask<Void, Void, Void> myAsyncTask = new AsyncTask<Void, Void, Void>() {
|
|
159
162
|
@Override
|
|
160
|
-
protected Void doInBackground(final Void
|
|
163
|
+
protected Void doInBackground(final Void... params) {
|
|
161
164
|
Context context = getReactApplicationContext();
|
|
162
165
|
ContentResolver cr = context.getContentResolver();
|
|
163
166
|
ContactsProvider contactsProvider = new ContactsProvider(cr);
|
|
@@ -172,15 +175,16 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
172
175
|
|
|
173
176
|
/**
|
|
174
177
|
* Retrieves contacts matching an email address.
|
|
175
|
-
* Uses raw URI when <code>rawUri</code> is <code>true</code>, makes assets copy
|
|
178
|
+
* Uses raw URI when <code>rawUri</code> is <code>true</code>, makes assets copy
|
|
179
|
+
* otherwise.
|
|
176
180
|
*
|
|
177
181
|
* @param emailAddress email address to match
|
|
178
182
|
*/
|
|
179
183
|
@ReactMethod
|
|
180
184
|
public void getContactsByEmailAddress(final String emailAddress, final Promise promise) {
|
|
181
|
-
AsyncTask<Void,Void,Void> myAsyncTask = new AsyncTask<Void,Void,Void>() {
|
|
185
|
+
AsyncTask<Void, Void, Void> myAsyncTask = new AsyncTask<Void, Void, Void>() {
|
|
182
186
|
@Override
|
|
183
|
-
protected Void doInBackground(final Void
|
|
187
|
+
protected Void doInBackground(final Void... params) {
|
|
184
188
|
Context context = getReactApplicationContext();
|
|
185
189
|
ContentResolver cr = context.getContentResolver();
|
|
186
190
|
ContactsProvider contactsProvider = new ContactsProvider(cr);
|
|
@@ -194,15 +198,16 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
194
198
|
}
|
|
195
199
|
|
|
196
200
|
/**
|
|
197
|
-
* Retrieves <code>thumbnailPath</code> for contact, or <code>null</code> if not
|
|
201
|
+
* Retrieves <code>thumbnailPath</code> for contact, or <code>null</code> if not
|
|
202
|
+
* available.
|
|
198
203
|
*
|
|
199
204
|
* @param contactId contact identifier, <code>recordID</code>
|
|
200
205
|
*/
|
|
201
206
|
@ReactMethod
|
|
202
207
|
public void getPhotoForId(final String contactId, final Promise promise) {
|
|
203
|
-
AsyncTask<Void,Void,Void> myAsyncTask = new AsyncTask<Void,Void,Void>() {
|
|
208
|
+
AsyncTask<Void, Void, Void> myAsyncTask = new AsyncTask<Void, Void, Void>() {
|
|
204
209
|
@Override
|
|
205
|
-
protected Void doInBackground(final Void
|
|
210
|
+
protected Void doInBackground(final Void... params) {
|
|
206
211
|
Context context = getReactApplicationContext();
|
|
207
212
|
ContentResolver cr = context.getContentResolver();
|
|
208
213
|
ContactsProvider contactsProvider = new ContactsProvider(cr);
|
|
@@ -216,15 +221,16 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
216
221
|
}
|
|
217
222
|
|
|
218
223
|
/**
|
|
219
|
-
* Retrieves <code>contact</code> for contact, or <code>null</code> if not
|
|
224
|
+
* Retrieves <code>contact</code> for contact, or <code>null</code> if not
|
|
225
|
+
* available.
|
|
220
226
|
*
|
|
221
227
|
* @param contactId contact identifier, <code>recordID</code>
|
|
222
228
|
*/
|
|
223
229
|
@ReactMethod
|
|
224
230
|
public void getContactById(final String contactId, final Promise promise) {
|
|
225
|
-
AsyncTask<Void,Void,Void> myAsyncTask = new AsyncTask<Void,Void,Void>() {
|
|
231
|
+
AsyncTask<Void, Void, Void> myAsyncTask = new AsyncTask<Void, Void, Void>() {
|
|
226
232
|
@Override
|
|
227
|
-
protected Void doInBackground(final Void
|
|
233
|
+
protected Void doInBackground(final Void... params) {
|
|
228
234
|
Context context = getReactApplicationContext();
|
|
229
235
|
ContentResolver cr = context.getContentResolver();
|
|
230
236
|
ContactsProvider contactsProvider = new ContactsProvider(cr);
|
|
@@ -239,9 +245,9 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
239
245
|
|
|
240
246
|
@ReactMethod
|
|
241
247
|
public void writePhotoToPath(final String contactId, final String file, final Promise promise) {
|
|
242
|
-
AsyncTask<Void,Void,Void> myAsyncTask = new AsyncTask<Void,Void,Void>() {
|
|
248
|
+
AsyncTask<Void, Void, Void> myAsyncTask = new AsyncTask<Void, Void, Void>() {
|
|
243
249
|
@Override
|
|
244
|
-
protected Void doInBackground(final Void
|
|
250
|
+
protected Void doInBackground(final Void... params) {
|
|
245
251
|
Context context = getReactApplicationContext();
|
|
246
252
|
ContentResolver cr = context.getContentResolver();
|
|
247
253
|
|
|
@@ -279,7 +285,7 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
279
285
|
if (photo == null) {
|
|
280
286
|
// Try to find the thumbnail from assets
|
|
281
287
|
AssetManager assetManager = getReactApplicationContext().getAssets();
|
|
282
|
-
InputStream
|
|
288
|
+
InputStream inputStream = null;
|
|
283
289
|
try {
|
|
284
290
|
inputStream = assetManager.open(thumbnailPath);
|
|
285
291
|
photo = BitmapFactory.decodeStream(inputStream);
|
|
@@ -455,16 +461,17 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
455
461
|
structuredPostal.put(CommonDataKinds.StructuredPostal.REGION, postalAddressesRegion[i]);
|
|
456
462
|
structuredPostal.put(CommonDataKinds.StructuredPostal.COUNTRY, postalAddressesCountry[i]);
|
|
457
463
|
structuredPostal.put(CommonDataKinds.StructuredPostal.POSTCODE, postalAddressesPostCode[i]);
|
|
458
|
-
structuredPostal.put(CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS,
|
|
464
|
+
structuredPostal.put(CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS,
|
|
465
|
+
postalAddressesFormattedAddress[i]);
|
|
459
466
|
structuredPostal.put(CommonDataKinds.StructuredPostal.LABEL, postalAddressesLabel[i]);
|
|
460
467
|
structuredPostal.put(CommonDataKinds.StructuredPostal.TYPE, postalAddressesType[i]);
|
|
461
|
-
//No state column in StructuredPostal
|
|
462
|
-
//structuredPostal.put(CommonDataKinds.StructuredPostal.???,
|
|
468
|
+
// No state column in StructuredPostal
|
|
469
|
+
// structuredPostal.put(CommonDataKinds.StructuredPostal.???,
|
|
470
|
+
// postalAddressesState[i]);
|
|
463
471
|
contactData.add(structuredPostal);
|
|
464
472
|
}
|
|
465
473
|
|
|
466
|
-
for (int i = 0; i < numOfIMAddresses; i++)
|
|
467
|
-
{
|
|
474
|
+
for (int i = 0; i < numOfIMAddresses; i++) {
|
|
468
475
|
ContentValues imAddress = new ContentValues();
|
|
469
476
|
imAddress.put(ContactsContract.Data.MIMETYPE, CommonDataKinds.Im.CONTENT_ITEM_TYPE);
|
|
470
477
|
imAddress.put(CommonDataKinds.Im.DATA, imAccounts[i]);
|
|
@@ -474,22 +481,22 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
474
481
|
contactData.add(imAddress);
|
|
475
482
|
}
|
|
476
483
|
|
|
477
|
-
if(note != null) {
|
|
484
|
+
if (note != null) {
|
|
478
485
|
ContentValues structuredNote = new ContentValues();
|
|
479
486
|
structuredNote.put(ContactsContract.Data.MIMETYPE, Note.CONTENT_ITEM_TYPE);
|
|
480
487
|
structuredNote.put(ContactsContract.CommonDataKinds.Note.NOTE, note);
|
|
481
488
|
contactData.add(structuredNote);
|
|
482
489
|
}
|
|
483
490
|
|
|
484
|
-
if(thumbnailPath != null && !thumbnailPath.isEmpty()) {
|
|
491
|
+
if (thumbnailPath != null && !thumbnailPath.isEmpty()) {
|
|
485
492
|
Bitmap photo = getThumbnailBitmap(thumbnailPath);
|
|
486
493
|
|
|
487
|
-
if(photo != null) {
|
|
494
|
+
if (photo != null) {
|
|
488
495
|
ContentValues thumbnail = new ContentValues();
|
|
489
496
|
thumbnail.put(ContactsContract.Data.RAW_CONTACT_ID, 0);
|
|
490
497
|
thumbnail.put(ContactsContract.Data.IS_SUPER_PRIMARY, 1);
|
|
491
498
|
thumbnail.put(ContactsContract.CommonDataKinds.Photo.PHOTO, toByteArray(photo));
|
|
492
|
-
thumbnail.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE
|
|
499
|
+
thumbnail.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
|
|
493
500
|
contactData.add(thumbnail);
|
|
494
501
|
}
|
|
495
502
|
}
|
|
@@ -525,7 +532,7 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
525
532
|
}
|
|
526
533
|
}
|
|
527
534
|
|
|
528
|
-
|
|
535
|
+
/*
|
|
529
536
|
* View contact in native app
|
|
530
537
|
*/
|
|
531
538
|
@ReactMethod
|
|
@@ -546,7 +553,7 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
546
553
|
promise.reject(e.toString());
|
|
547
554
|
}
|
|
548
555
|
}
|
|
549
|
-
|
|
556
|
+
|
|
550
557
|
/*
|
|
551
558
|
* Edit contact in native app
|
|
552
559
|
*/
|
|
@@ -708,7 +715,7 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
708
715
|
.withValue(Organization.DEPARTMENT, department);
|
|
709
716
|
ops.add(op.build());
|
|
710
717
|
|
|
711
|
-
//TODO not sure where to allow yields
|
|
718
|
+
// TODO not sure where to allow yields
|
|
712
719
|
op.withYieldAllowed(true);
|
|
713
720
|
|
|
714
721
|
for (int i = 0; i < numOfPhones; i++) {
|
|
@@ -739,13 +746,14 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
739
746
|
ops.add(op.build());
|
|
740
747
|
}
|
|
741
748
|
|
|
742
|
-
if(thumbnailPath != null && !thumbnailPath.isEmpty()) {
|
|
749
|
+
if (thumbnailPath != null && !thumbnailPath.isEmpty()) {
|
|
743
750
|
Bitmap photo = getThumbnailBitmap(thumbnailPath);
|
|
744
751
|
|
|
745
|
-
if(photo != null) {
|
|
752
|
+
if (photo != null) {
|
|
746
753
|
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
|
747
754
|
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
|
748
|
-
.withValue(ContactsContract.Data.MIMETYPE,
|
|
755
|
+
.withValue(ContactsContract.Data.MIMETYPE,
|
|
756
|
+
ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
|
749
757
|
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, toByteArray(photo))
|
|
750
758
|
.build());
|
|
751
759
|
}
|
|
@@ -759,7 +767,8 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
759
767
|
op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
|
760
768
|
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
|
761
769
|
.withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)
|
|
762
|
-
.withValue(CommonDataKinds.StructuredPostal.TYPE,
|
|
770
|
+
.withValue(CommonDataKinds.StructuredPostal.TYPE,
|
|
771
|
+
mapStringToPostalAddressType(address.getString("label")))
|
|
763
772
|
.withValue(CommonDataKinds.StructuredPostal.LABEL, address.getString("label"))
|
|
764
773
|
.withValue(CommonDataKinds.StructuredPostal.STREET, address.getString("street"))
|
|
765
774
|
.withValue(CommonDataKinds.StructuredPostal.CITY, address.getString("city"))
|
|
@@ -771,8 +780,7 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
771
780
|
}
|
|
772
781
|
}
|
|
773
782
|
|
|
774
|
-
for (int i = 0; i < numOfIMAddresses; i++)
|
|
775
|
-
{
|
|
783
|
+
for (int i = 0; i < numOfIMAddresses; i++) {
|
|
776
784
|
op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
|
777
785
|
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
|
778
786
|
.withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Im.CONTENT_ITEM_TYPE)
|
|
@@ -788,7 +796,7 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
788
796
|
ContentResolver cr = ctx.getContentResolver();
|
|
789
797
|
ContentProviderResult[] result = cr.applyBatch(ContactsContract.AUTHORITY, ops);
|
|
790
798
|
|
|
791
|
-
if(result != null && result.length > 0) {
|
|
799
|
+
if (result != null && result.length > 0) {
|
|
792
800
|
|
|
793
801
|
String rawId = String.valueOf(ContentUris.parseId(result[0].uri));
|
|
794
802
|
|
|
@@ -919,9 +927,9 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
919
927
|
for (int i = 0; i < numOfPostalAddresses; i++) {
|
|
920
928
|
String postalLabel = getValueFromKey(postalAddresses.getMap(i), "label");
|
|
921
929
|
postalAddressesStreet[i] = getValueFromKey(postalAddresses.getMap(i), "street");
|
|
922
|
-
postalAddressesCity[i] =
|
|
930
|
+
postalAddressesCity[i] = getValueFromKey(postalAddresses.getMap(i), "city");
|
|
923
931
|
postalAddressesState[i] = getValueFromKey(postalAddresses.getMap(i), "state");
|
|
924
|
-
postalAddressesRegion[i] = getValueFromKey(postalAddresses.getMap(i),"region");
|
|
932
|
+
postalAddressesRegion[i] = getValueFromKey(postalAddresses.getMap(i), "region");
|
|
925
933
|
postalAddressesPostCode[i] = getValueFromKey(postalAddresses.getMap(i), "postCode");
|
|
926
934
|
postalAddressesCountry[i] = getValueFromKey(postalAddresses.getMap(i), "country");
|
|
927
935
|
postalAddressesType[i] = mapStringToPostalAddressType(postalLabel);
|
|
@@ -951,7 +959,7 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
951
959
|
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
|
|
952
960
|
|
|
953
961
|
ContentProviderOperation.Builder op = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
|
954
|
-
.withSelection(ContactsContract.Data.CONTACT_ID + "=?", new String[]{String.valueOf(recordID)})
|
|
962
|
+
.withSelection(ContactsContract.Data.CONTACT_ID + "=?", new String[] { String.valueOf(recordID) })
|
|
955
963
|
.withValue(ContactsContract.Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
|
|
956
964
|
.withValue(StructuredName.GIVEN_NAME, givenName)
|
|
957
965
|
.withValue(StructuredName.MIDDLE_NAME, middleName)
|
|
@@ -961,7 +969,8 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
961
969
|
ops.add(op.build());
|
|
962
970
|
|
|
963
971
|
op = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
|
964
|
-
.withSelection(ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + " = ?",
|
|
972
|
+
.withSelection(ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + " = ?",
|
|
973
|
+
new String[] { String.valueOf(recordID), Organization.CONTENT_ITEM_TYPE })
|
|
965
974
|
.withValue(Organization.COMPANY, company)
|
|
966
975
|
.withValue(Organization.TITLE, jobTitle)
|
|
967
976
|
.withValue(Organization.DEPARTMENT, department);
|
|
@@ -969,14 +978,13 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
969
978
|
|
|
970
979
|
op.withYieldAllowed(true);
|
|
971
980
|
|
|
972
|
-
|
|
973
981
|
if (phoneNumbers != null) {
|
|
974
982
|
// remove existing phoneNumbers first
|
|
975
983
|
op = ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
|
976
984
|
.withSelection(
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
985
|
+
ContactsContract.Data.MIMETYPE + "=? AND " + ContactsContract.Data.RAW_CONTACT_ID + " = ?",
|
|
986
|
+
new String[] { String.valueOf(CommonDataKinds.Phone.CONTENT_ITEM_TYPE),
|
|
987
|
+
String.valueOf(rawContactId) });
|
|
980
988
|
ops.add(op.build());
|
|
981
989
|
|
|
982
990
|
// add passed phonenumbers
|
|
@@ -999,19 +1007,19 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
999
1007
|
.withValue(CommonDataKinds.Website.URL, urls[i]);
|
|
1000
1008
|
} else {
|
|
1001
1009
|
op = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
|
1002
|
-
.withSelection(ContactsContract.Data._ID + "=?", new String[]{String.valueOf(urlIds[i])})
|
|
1010
|
+
.withSelection(ContactsContract.Data._ID + "=?", new String[] { String.valueOf(urlIds[i]) })
|
|
1003
1011
|
.withValue(CommonDataKinds.Website.URL, urls[i]);
|
|
1004
1012
|
}
|
|
1005
1013
|
ops.add(op.build());
|
|
1006
1014
|
}
|
|
1007
1015
|
|
|
1008
|
-
if (emailAddresses != null){
|
|
1016
|
+
if (emailAddresses != null) {
|
|
1009
1017
|
// remove existing emails first
|
|
1010
1018
|
op = ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
|
1011
1019
|
.withSelection(
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1020
|
+
ContactsContract.Data.MIMETYPE + "=? AND " + ContactsContract.Data.RAW_CONTACT_ID + " = ?",
|
|
1021
|
+
new String[] { String.valueOf(CommonDataKinds.Email.CONTENT_ITEM_TYPE),
|
|
1022
|
+
String.valueOf(rawContactId) });
|
|
1015
1023
|
ops.add(op.build());
|
|
1016
1024
|
|
|
1017
1025
|
// add passed email addresses
|
|
@@ -1029,12 +1037,11 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
1029
1037
|
// remove existing note first
|
|
1030
1038
|
op = ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
|
1031
1039
|
.withSelection(
|
|
1032
|
-
ContactsContract.Data.MIMETYPE
|
|
1033
|
-
new String[]{String.valueOf(Note.CONTENT_ITEM_TYPE), String.valueOf(rawContactId)}
|
|
1034
|
-
);
|
|
1040
|
+
ContactsContract.Data.MIMETYPE + "=? AND " + ContactsContract.Data.RAW_CONTACT_ID + " = ?",
|
|
1041
|
+
new String[] { String.valueOf(Note.CONTENT_ITEM_TYPE), String.valueOf(rawContactId) });
|
|
1035
1042
|
ops.add(op.build());
|
|
1036
1043
|
|
|
1037
|
-
if(note != null) {
|
|
1044
|
+
if (note != null) {
|
|
1038
1045
|
op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
|
1039
1046
|
.withValue(ContactsContract.Data.RAW_CONTACT_ID, String.valueOf(rawContactId))
|
|
1040
1047
|
.withValue(ContactsContract.Data.MIMETYPE, Note.CONTENT_ITEM_TYPE)
|
|
@@ -1042,25 +1049,26 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
1042
1049
|
ops.add(op.build());
|
|
1043
1050
|
}
|
|
1044
1051
|
|
|
1045
|
-
if(thumbnailPath != null && !thumbnailPath.isEmpty()) {
|
|
1052
|
+
if (thumbnailPath != null && !thumbnailPath.isEmpty()) {
|
|
1046
1053
|
Bitmap photo = getThumbnailBitmap(thumbnailPath);
|
|
1047
1054
|
|
|
1048
|
-
if(photo != null) {
|
|
1055
|
+
if (photo != null) {
|
|
1049
1056
|
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
|
1050
1057
|
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
|
1051
|
-
.withValue(ContactsContract.Data.MIMETYPE,
|
|
1058
|
+
.withValue(ContactsContract.Data.MIMETYPE,
|
|
1059
|
+
ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
|
1052
1060
|
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, toByteArray(photo))
|
|
1053
1061
|
.build());
|
|
1054
1062
|
}
|
|
1055
1063
|
}
|
|
1056
1064
|
|
|
1057
|
-
if (postalAddresses != null){
|
|
1058
|
-
//remove existing addresses
|
|
1059
|
-
|
|
1065
|
+
if (postalAddresses != null) {
|
|
1066
|
+
// remove existing addresses
|
|
1067
|
+
op = ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
|
1060
1068
|
.withSelection(
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1069
|
+
ContactsContract.Data.MIMETYPE + "=? AND " + ContactsContract.Data.RAW_CONTACT_ID + " = ?",
|
|
1070
|
+
new String[] { String.valueOf(CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE),
|
|
1071
|
+
String.valueOf(rawContactId) });
|
|
1064
1072
|
ops.add(op.build());
|
|
1065
1073
|
|
|
1066
1074
|
for (int i = 0; i < numOfPostalAddresses; i++) {
|
|
@@ -1078,13 +1086,13 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
1078
1086
|
}
|
|
1079
1087
|
}
|
|
1080
1088
|
|
|
1081
|
-
if (imAddresses != null){
|
|
1089
|
+
if (imAddresses != null) {
|
|
1082
1090
|
// remove existing IM addresses
|
|
1083
1091
|
op = ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
|
1084
1092
|
.withSelection(
|
|
1085
|
-
ContactsContract.Data.MIMETYPE
|
|
1086
|
-
new String[]{String.valueOf(CommonDataKinds.Im.CONTENT_ITEM_TYPE),
|
|
1087
|
-
|
|
1093
|
+
ContactsContract.Data.MIMETYPE + "=? AND " + ContactsContract.Data.RAW_CONTACT_ID + " = ?",
|
|
1094
|
+
new String[] { String.valueOf(CommonDataKinds.Im.CONTENT_ITEM_TYPE),
|
|
1095
|
+
String.valueOf(rawContactId) });
|
|
1088
1096
|
ops.add(op.build());
|
|
1089
1097
|
|
|
1090
1098
|
// add passed IM addresses
|
|
@@ -1105,7 +1113,7 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
1105
1113
|
ContentResolver cr = ctx.getContentResolver();
|
|
1106
1114
|
ContentProviderResult[] result = cr.applyBatch(ContactsContract.AUTHORITY, ops);
|
|
1107
1115
|
|
|
1108
|
-
if(result != null && result.length > 0) {
|
|
1116
|
+
if (result != null && result.length > 0) {
|
|
1109
1117
|
|
|
1110
1118
|
ContactsProvider contactsProvider = new ContactsProvider(cr);
|
|
1111
1119
|
WritableMap updatedContact = contactsProvider.getContactById(recordID);
|
|
@@ -1126,21 +1134,22 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
1126
1134
|
String recordID = contact.hasKey("recordID") ? contact.getString("recordID") : null;
|
|
1127
1135
|
|
|
1128
1136
|
try {
|
|
1129
|
-
|
|
1137
|
+
Context ctx = getReactApplicationContext();
|
|
1130
1138
|
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1139
|
+
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, recordID);
|
|
1140
|
+
ContentResolver cr = ctx.getContentResolver();
|
|
1141
|
+
int deleted = cr.delete(uri, null, null);
|
|
1134
1142
|
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1143
|
+
if (deleted > 0)
|
|
1144
|
+
promise.resolve(recordID); // success
|
|
1145
|
+
else
|
|
1146
|
+
promise.resolve(null); // something was wrong
|
|
1139
1147
|
|
|
1140
1148
|
} catch (Exception e) {
|
|
1141
1149
|
promise.reject(e.toString());
|
|
1142
1150
|
}
|
|
1143
1151
|
}
|
|
1152
|
+
|
|
1144
1153
|
/*
|
|
1145
1154
|
* Check permission
|
|
1146
1155
|
*/
|
|
@@ -1178,11 +1187,12 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
1178
1187
|
}
|
|
1179
1188
|
|
|
1180
1189
|
requestPromise = promise;
|
|
1181
|
-
ActivityCompat.requestPermissions(currentActivity, new String[]{PERMISSION_READ_CONTACTS},
|
|
1190
|
+
ActivityCompat.requestPermissions(currentActivity, new String[] { PERMISSION_READ_CONTACTS },
|
|
1191
|
+
PERMISSION_REQUEST_CODE);
|
|
1182
1192
|
}
|
|
1183
1193
|
|
|
1184
1194
|
protected static void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
|
|
1185
|
-
|
|
1195
|
+
@NonNull int[] grantResults) {
|
|
1186
1196
|
if (requestPromise == null) {
|
|
1187
1197
|
return;
|
|
1188
1198
|
}
|
|
@@ -1218,13 +1228,14 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
1218
1228
|
*/
|
|
1219
1229
|
private String isPermissionGranted() {
|
|
1220
1230
|
// return -1 for denied and 1
|
|
1221
|
-
int res = getReactApplicationContext()
|
|
1231
|
+
int res = ActivityCompat.checkSelfPermission(getReactApplicationContext(), PERMISSION_READ_CONTACTS);
|
|
1222
1232
|
return (res == PackageManager.PERMISSION_GRANTED) ? PERMISSION_AUTHORIZED : PERMISSION_DENIED;
|
|
1223
1233
|
}
|
|
1224
1234
|
|
|
1225
1235
|
/*
|
|
1226
1236
|
* TODO support all phone types
|
|
1227
|
-
* http://developer.android.com/reference/android/provider/ContactsContract.
|
|
1237
|
+
* http://developer.android.com/reference/android/provider/ContactsContract.
|
|
1238
|
+
* CommonDataKinds.Phone.html
|
|
1228
1239
|
*/
|
|
1229
1240
|
private int mapStringToPhoneType(String label) {
|
|
1230
1241
|
int phoneType;
|
|
@@ -1271,7 +1282,8 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
1271
1282
|
|
|
1272
1283
|
/*
|
|
1273
1284
|
* TODO support TYPE_CUSTOM
|
|
1274
|
-
* http://developer.android.com/reference/android/provider/ContactsContract.
|
|
1285
|
+
* http://developer.android.com/reference/android/provider/ContactsContract.
|
|
1286
|
+
* CommonDataKinds.Email.html
|
|
1275
1287
|
*/
|
|
1276
1288
|
private int mapStringToEmailType(String label) {
|
|
1277
1289
|
int emailType;
|
|
@@ -1316,7 +1328,7 @@ public class ContactsManager extends ReactContextBaseJavaModule implements Activ
|
|
|
1316
1328
|
|
|
1317
1329
|
@Override
|
|
1318
1330
|
public String getName() {
|
|
1319
|
-
return
|
|
1331
|
+
return ContactsProvider.NAME;
|
|
1320
1332
|
}
|
|
1321
1333
|
|
|
1322
1334
|
/*
|
package/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export function getContactById(contactId: string): Promise<Contact | null>;
|
|
|
4
4
|
export function getCount(): Promise<number>;
|
|
5
5
|
export function getPhotoForId(contactId: string): Promise<string>;
|
|
6
6
|
export function addContact(contact: Partial<Contact>): Promise<Contact>;
|
|
7
|
-
export function openContactForm(contact: Partial<Contact>): Promise<Contact>;
|
|
7
|
+
export function openContactForm(contact: Partial<Contact>): Promise<Contact | null>;
|
|
8
8
|
export function openExistingContact(contact: Contact): Promise<Contact>;
|
|
9
9
|
export function viewExistingContact(contact: { recordID: string }): Promise<Contact | void>
|
|
10
10
|
export function editExistingContact(contact: Contact): Promise<Contact>;
|
|
@@ -49,7 +49,7 @@ export interface InstantMessageAddress {
|
|
|
49
49
|
export interface Birthday {
|
|
50
50
|
day: number;
|
|
51
51
|
month: number;
|
|
52
|
-
year
|
|
52
|
+
year?: number;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export interface UrlAddress {
|
|
@@ -62,21 +62,21 @@ export interface Contact {
|
|
|
62
62
|
backTitle: string;
|
|
63
63
|
company: string|null;
|
|
64
64
|
emailAddresses: EmailAddress[];
|
|
65
|
-
displayName: string;
|
|
65
|
+
displayName: string|null;
|
|
66
66
|
familyName: string;
|
|
67
|
-
givenName: string;
|
|
67
|
+
givenName: string|null;
|
|
68
68
|
middleName: string;
|
|
69
|
-
jobTitle: string;
|
|
69
|
+
jobTitle: string|null;
|
|
70
70
|
phoneNumbers: PhoneNumber[];
|
|
71
71
|
hasThumbnail: boolean;
|
|
72
72
|
thumbnailPath: string;
|
|
73
73
|
isStarred: boolean;
|
|
74
74
|
postalAddresses: PostalAddress[];
|
|
75
|
-
prefix: string;
|
|
76
|
-
suffix: string;
|
|
77
|
-
department: string;
|
|
78
|
-
birthday
|
|
75
|
+
prefix: string|null;
|
|
76
|
+
suffix: string|null;
|
|
77
|
+
department: string|null;
|
|
78
|
+
birthday?: Birthday;
|
|
79
79
|
imAddresses: InstantMessageAddress[];
|
|
80
80
|
urlAddresses: UrlAddress[];
|
|
81
|
-
note: string;
|
|
81
|
+
note: string|null;
|
|
82
82
|
}
|