Giter VIP home page Giter VIP logo

Comments (8)

Mahender-Prayuta avatar Mahender-Prayuta commented on June 6, 2024

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.

goderbauer avatar goderbauer commented on June 6, 2024

@Mahender-Prayuta Do you want to send a pull request with that change?

from contact_picker.

tjerkw avatar tjerkw commented on June 6, 2024

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.

tjerkw avatar tjerkw commented on June 6, 2024

@goderbauer after merging the pull request this issue should be resolved.

Nice library! Really appreciated!

from contact_picker.

AmandaDEn32 avatar AmandaDEn32 commented on June 6, 2024

is there any equivalent for contactscontract in flutter?

from contact_picker.

Mahi-K avatar Mahi-K commented on June 6, 2024

hi @AmandaDEn32 sorry, i didn't get your question. Could you please explain what you are trying to achieve? Thanks.

from contact_picker.

AmandaDEn32 avatar AmandaDEn32 commented on June 6, 2024

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.

harshOnAndroid avatar harshOnAndroid commented on June 6, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.