Comments (8)
Hi there,
I had the same problem, i think you need to change the android code as follows. I mean you need to edit the C:\your pub-cache directory\contact_picker-0.0.1+2\android\src\main\java\net\goderbauer\flutter\contactpicker\ContactPickerPlugin.java
to the following code
Android Code:
// 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<String, Object> phoneNumber = new HashMap<>();
phoneNumber.put("number", number);
phoneNumber.put("label", label);
HashMap<String, Object> contact = new HashMap<>();
contact.put("fullName", fullName);
contact.put("phoneNumber", phoneNumber);
pendingResult.success(contact);
pendingResult = null;
return true;
}
else{
pendingResult = null;
return false;
}
}
}
I hope this will solve your problem. please close the bug if this works.
Many thanks
Mahi
from contact_picker.
@Mahender-Prayuta Do you want to send a pull request with that change?
from contact_picker.
Same problem here!
E/AndroidRuntime( 4660): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2015, result=0, data=null} to activity {nl.boomrang.boomrangapp/nl.boomrang.boomrangapp.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.net.Uri android.content.Intent.getData()' on a null object reference
E/AndroidRuntime( 4660): at android.app.ActivityThread.deliverResults(ActivityThread.java:4324)
E/AndroidRuntime( 4660): at android.app.ActivityThread.handleSendResult(ActivityThread.java:4367)
E/AndroidRuntime( 4660): at android.app.ActivityThread.-wrap19(Unknown Source:0)
E/AndroidRuntime( 4660): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1649)
E/AndroidRuntime( 4660): at android.os.Handler.dispatchMessage(Handler.java:105)
E/AndroidRuntime( 4660): at android.os.Looper.loop(Looper.java:164)
E/AndroidRuntime( 4660): at android.app.ActivityThread.main(ActivityThread.java:6541)
E/AndroidRuntime( 4660): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 4660): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
E/AndroidRuntime( 4660): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
E/AndroidRuntime( 4660): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.net.Uri android.content.Intent.getData()' on a null object reference
E/AndroidRuntime( 4660): at net.goderbauer.flutter.contactpicker.ContactPickerPlugin.onActivityResult(ContactPickerPlugin.java:66)
E/AndroidRuntime( 4660): at io.flutter.app.FlutterPluginRegistry.onActivityResult(FlutterPluginRegistry.java:184)
E/AndroidRuntime( 4660): at io.flutter.app.FlutterActivityDelegate.onActivityResult(FlutterActivityDelegate.java:137)
E/AndroidRuntime( 4660): at io.flutter.app.FlutterActivity.onActivityResult(FlutterActivity.java:122)
E/AndroidRuntime( 4660): at android.app.Activity.dispatchActivityResult(Activity.java:7235)
E/AndroidRuntime( 4660): at android.app.ActivityThread.deliverResults(ActivityThread.java:4320)
E/AndroidRuntime( 4660): ... 9 more
from contact_picker.
@goderbauer after merging the pull request this issue should be resolved.
Nice library! Really appreciated!
from contact_picker.
is there any equivalent for contactscontract in flutter?
from contact_picker.
hi @AmandaDEn32 sorry, i didn't get your question. Could you please explain what you are trying to achieve? Thanks.
from contact_picker.
hi @Mahi-K , well i want to list the groups of contacts that i have created on my phone, how to do that with flutter?
from contact_picker.
I am having the same issue but with sms package. I think the bug is in CallLogPlugin.java file.
Can someone fix this? What should I do temporarily?
Below is my logcat-
java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=2, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.harsh.navigation/com.harsh.navigation.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'void io.flutter.plugin.common.MethodChannel$Result.error(java.lang.String, java.lang.String, java.lang.Object)' on a null object reference
E/AndroidRuntime(14043): at android.app.ActivityThread.deliverResults(ActivityThread.java:4324)
E/AndroidRuntime(14043): at android.app.ActivityThread.handleSendResult(ActivityThread.java:4367)
E/AndroidRuntime(14043): at android.app.ActivityThread.-wrap19(Unknown Source:0)
E/AndroidRuntime(14043): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1649)
E/AndroidRuntime(14043): at android.os.Handler.dispatchMessage(Handler.java:105)
E/AndroidRuntime(14043): at android.os.Looper.loop(Looper.java:164)
E/AndroidRuntime(14043): at android.app.ActivityThread.main(ActivityThread.java:6548)
E/AndroidRuntime(14043): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(14043): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
E/AndroidRuntime(14043): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
E/AndroidRuntime(14043): Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void io.flutter.plugin.common.MethodChannel$Result.error(java.lang.String, java.lang.String, java.lang.Object)' on a null object reference
E/AndroidRuntime(14043): at sk.fourq.calllog.CallLogPlugin.onRequestPermissionsResult(CallLogPlugin.java:66)
E/AndroidRuntime(14043): at io.flutter.app.FlutterPluginRegistry.onRequestPermissionsResult(FlutterPluginRegistry.java:191)
E/AndroidRuntime(14043): at io.flutter.app.FlutterActivityDelegate.onRequestPermissionsResult(FlutterActivityDelegate.java:125)
E/AndroidRuntime(14043): at io.flutter.app.FlutterActivity.onRequestPermissionsResult(FlutterActivity.java:133)
E/AndroidRuntime(14043): at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7425)
E/AndroidRuntime(14043): at android.app.Activity.dispatchActivityResult(Activity.java:7266)
E/AndroidRuntime(14043): at android.app.ActivityThread.deliverResults(ActivityThread.java:4320)
E/AndroidRuntime(14043): ... 9 more
from contact_picker.
Related Issues (20)
- Crashes on simulation on Android Device
- Add ability to retrieve IM accounts and the contact avatar
- If multiple requests are made, it results in a crash because pendingResult is set to null
- 多 FlutterActivity 收不到 onActivityResult 回调
- android X not supported HOT 4
- Caused incorrect action on MI 9
- if you try to reselect the contact it does not select
- app crashes when we access from phonebook HOT 7
- How to change background color and text color according my theme?.
- iOS is unsupported? HOT 1
- Maintenance status HOT 10
- plugin not support android HOT 2
- Can not build APK HOT 3
- 'CNContactPickerViewController' is only available on iOS 9.0 or newer
- Execution failed for task ':contact_picker:lint'.
- :contact_picker:verifyReleaseResources on release build HOT 1
- No Pubspec Found
- use a deprecated version of the Android embedding.
- Please Update this to Null Safty HOT 1
- Need Null Safety
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from contact_picker.