Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rootProject.allprojects {
apply plugin: 'com.android.library'

android {
namespace "flutter.plugins.contactsservice.contactsservice"
compileSdkVersion 30

defaultConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private Contact() {
}

String identifier;
String displayName, givenName, middleName, familyName, prefix, suffix, company, jobTitle, note, birthday, androidAccountType, androidAccountName;
String displayName, givenName, middleName, familyName, prefix, suffix, company, jobTitle, note, birthday, androidAccountType, androidAccountName, sourceId;
ArrayList<Item> emails = new ArrayList<>();
ArrayList<Item> phones = new ArrayList<>();
ArrayList<PostalAddress> postalAddresses = new ArrayList<>();
Expand All @@ -35,6 +35,7 @@ HashMap<String, Object> toMap() {
contactMap.put("birthday", birthday);
contactMap.put("androidAccountType", androidAccountType);
contactMap.put("androidAccountName", androidAccountName);
contactMap.put("sourceId", sourceId);

ArrayList<HashMap<String, String>> emailsMap = new ArrayList<>();
for (Item email : emails) {
Expand Down Expand Up @@ -73,6 +74,7 @@ static Contact fromMap(HashMap map) {
contact.birthday = (String) map.get("birthday");
contact.androidAccountType = (String) map.get("androidAccountType");
contact.androidAccountName = (String) map.get("androidAccountName");
contact.sourceId = (String) map.get("sourceId");

ArrayList<HashMap> emails = (ArrayList<HashMap>) map.get("emails");
if (emails != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public void onMethodCall(MethodCall call, Result result) {
ContactsContract.Contacts.Data.MIMETYPE,
ContactsContract.RawContacts.ACCOUNT_TYPE,
ContactsContract.RawContacts.ACCOUNT_NAME,
ContactsContract.RawContacts.SOURCE_ID,
StructuredName.DISPLAY_NAME,
StructuredName.GIVEN_NAME,
StructuredName.MIDDLE_NAME,
Expand Down Expand Up @@ -271,6 +272,10 @@ void finishWithResult(Object result) {

@Override
public boolean onActivityResult(int requestCode, int resultCode, Intent intent) {
if (intent == null) {
return true;
}

if(requestCode == REQUEST_OPEN_EXISTING_CONTACT || requestCode == REQUEST_OPEN_CONTACT_FORM) {
try {
Uri ur = intent.getData();
Expand All @@ -286,16 +291,16 @@ public boolean onActivityResult(int requestCode, int resultCode, Intent intent)
finishWithResult(FORM_OPERATION_CANCELED);
return true;
}

Uri contactUri = intent.getData();
if (intent != null){
Cursor cursor = contentResolver.query(contactUri, null, null, null, null);
if (cursor.moveToFirst()) {
String id = contactUri.getLastPathSegment();
getContacts("openDeviceContactPicker", id, false, false, false, localizedLabels, this.result);
} else {
Log.e(LOG_TAG, "onActivityResult - cursor.moveToFirst() returns false");
finishWithResult(FORM_OPERATION_CANCELED);
}}else{return true;}
}
cursor.close();
return true;
}
Expand Down Expand Up @@ -575,6 +580,7 @@ private ArrayList<Contact> getContactsFrom(Cursor cursor, boolean localizedLabel
contact.displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
contact.androidAccountType = cursor.getString(cursor.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE));
contact.androidAccountName = cursor.getString(cursor.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_NAME));
contact.sourceId = cursor.getString(cursor.getColumnIndex(ContactsContract.RawContacts.SOURCE_ID));

//NAMES
if (mimeType.equals(CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)) {
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ flutter {
dependencies {
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'
}
}
7 changes: 6 additions & 1 deletion lib/contacts_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class Contact {
this.androidAccountType,
this.androidAccountTypeRaw,
this.androidAccountName,
this.sourceId,
});

String? identifier,
Expand All @@ -207,7 +208,7 @@ class Contact {
familyName,
company,
jobTitle;
String? androidAccountTypeRaw, androidAccountName;
String? androidAccountTypeRaw, androidAccountName, sourceId;
AndroidAccountType? androidAccountType;
List<Item>? emails = [];
List<Item>? phones = [];
Expand All @@ -234,6 +235,7 @@ class Contact {
androidAccountTypeRaw = m["androidAccountType"];
androidAccountType = accountTypeFromString(androidAccountTypeRaw);
androidAccountName = m["androidAccountName"];
sourceId = m["sourceId"];
emails = (m["emails"] as List?)?.map((m) => Item.fromMap(m)).toList();
phones = (m["phones"] as List?)?.map((m) => Item.fromMap(m)).toList();
postalAddresses = (m["postalAddresses"] as List?)
Expand Down Expand Up @@ -300,6 +302,7 @@ class Contact {
jobTitle: this.jobTitle ?? other.jobTitle,
androidAccountType: this.androidAccountType ?? other.androidAccountType,
androidAccountName: this.androidAccountName ?? other.androidAccountName,
sourceId: this.sourceId ?? other.sourceId,
emails: this.emails == null
? other.emails
: this
Expand Down Expand Up @@ -338,6 +341,7 @@ class Contact {
this.jobTitle == other.jobTitle &&
this.androidAccountType == other.androidAccountType &&
this.androidAccountName == other.androidAccountName &&
this.sourceId == other.sourceId &&
this.middleName == other.middleName &&
this.prefix == other.prefix &&
this.suffix == other.suffix &&
Expand All @@ -359,6 +363,7 @@ class Contact {
this.jobTitle,
this.androidAccountType,
this.androidAccountName,
this.sourceId,
this.middleName,
this.prefix,
this.suffix,
Expand Down
1 change: 1 addition & 0 deletions test/contacts_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ void main() {
"jobTitle": null,
"androidAccountType": null,
"androidAccountName": null,
"sourceId": null,
"emails": [],
"phones": [],
"postalAddresses": [],
Expand Down