Open KarunJose opened 5 years ago
same here. When i select the contact on android, the app crashes. WOrks on ios.
The same
Same issue. I get the contact in terminal, though.
Facing the same issues. Does anyone found a solution for this?
I'm too facing this issue
this worked for me As per stackoverflow answer -You need to edit the following file C:\your pub-cache directory\contact_picker-0.0.1+2\android\src\main\java\net\goderbauer\flutter\contactpicker\ContactPickerPlugin.java and replace with the following code. https://stackoverflow.com/questions/60566037/flutter-contact-picker `
// Copyright 2017 Michael Goderbauer. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package net.goderbauer.flutter.contactpicker;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import java.util.HashMap;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import static android.app.Activity.RESULT_OK;
public class ContactPickerPlugin implements MethodCallHandler, PluginRegistry.ActivityResultListener {
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "contact_picker");
ContactPickerPlugin instance = new ContactPickerPlugin(registrar.activity());
registrar.addActivityResultListener(instance);
channel.setMethodCallHandler(instance);
}
private ContactPickerPlugin(Activity activity) {
this.activity = activity;
}
private static int PICK_CONTACT = 2015;
private Activity activity;
private Result pendingResult = null;
@Override
public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("selectContact")) {
if (pendingResult != null) {
pendingResult.error("multiple_requests", "Cancelled by a second request.", null);
pendingResult = null;
}
pendingResult = result;
Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
activity.startActivityForResult(i, PICK_CONTACT);
} else {
//result.notImplemented();
pendingResult = null;
}
}
@Override
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode != PICK_CONTACT) {
return false;
}
if (resultCode != RESULT_OK) {
pendingResult.success(null);
pendingResult = null;
}
if(pendingResult != null){
Uri contactUri = data.getData();
Cursor cursor = activity.getContentResolver().query(contactUri, null, null, null, null);
cursor.moveToFirst();
int phoneType = cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
String customLabel = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LABEL));
String label = (String) ContactsContract.CommonDataKinds.Email.getTypeLabel(activity.getResources(), phoneType, customLabel);
String number = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
String fullName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
HashMap phoneNumber = new HashMap();
phoneNumber.put("number", number);
phoneNumber.put("label", label);
HashMap contact = new HashMap();
contact.put("fullName", fullName);
contact.put("phoneNumber", phoneNumber);
pendingResult.success(contact);
pendingResult = null;
return true;
}
else{
pendingResult = null;
return false;
}
}
}`
having the same issue. it was working fine untill it suddenly started breaking
while we click contacts from phonebook, the app suddenly crashed. But there was no issue in the previous versions