-1

Am work same project and i download multicontact library it give me only contact name what i went is contact number i change string to int but it didn't work can anyone now way

This is may code

public class MainActivity extends AppCompatActivity {

private static final int CONTACT_PICKER_REQUEST = 91;
public TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button btnOpenPicker = (Button) findViewById(R.id.btnOpenPicker);
    textView = (TextView)findViewById(R.id.textView);
    btnOpenPicker.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
                new MultiContactPicker.Builder(MainActivity.this) //Activity/fragment context
                        .theme(R.style.MyCustomPickerTheme) //Optional - default: MultiContactPicker.Azure
                        .hideScrollbar(false) //Optional - default: false
                        .showTrack(true) //Optional - default: true
                        .searchIconColor(Color.WHITE) //Optional - default: White
                        .setChoiceMode(MultiContactPicker.CHOICE_MODE_MULTIPLE) //Optional - default: CHOICE_MODE_MULTIPLE
                        .handleColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary)) //Optional - default: Azure Blue
                        .bubbleColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary)) //Optional - default: Azure Blue
                        .bubbleTextColor(Color.WHITE) //Optional - default: White
                        .showPickerForResult(CONTACT_PICKER_REQUEST);
            }else{
                Toast.makeText(MainActivity.this, "Remember to go into settings and enable the contacts permission.", Toast.LENGTH_LONG).show();
            }
        }



    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    String phoneNo = null ;
    if(requestCode == CONTACT_PICKER_REQUEST){
        if(resultCode == RESULT_OK) {
            List<ContactResult> results = MultiContactPicker.obtainResult(data);
          //  Log.d("MyTag", results.get(0).getPhoneNumbers());
           phoneNo =results.get(0).getPhoneNumbers();
            textView.setText(phoneNo);
                    Toast.makeText(MainActivity.this, ("bbbbbbbbbbbbbbbb" + phoneNo ),Toast.LENGTH_LONG).show();
        } else if(resultCode == RESULT_CANCELED){
            System.out.println("User closed the picker without selecting items.");
        }
    }
}

} Please can you fix it

2 Answers2

1

getPhoneNumbers() returns a List of type string.Try

List<String> phoneNumbers = results.get(0).getPhoneNumbers()
for(int i=0;i<phoneNumbers.length.size();i++)
   phoneNumbers.get(i);//This gives you the phone numbers
Suhas Ts
  • 317
  • 1
  • 11
0

you could try this:

String str = results.get(0).getContactID(); //this also return String 
int i = Integer.parseInt(str); //convert it to int
navylover
  • 12,383
  • 5
  • 28
  • 41
  • It work but am working on String str = results.get(0).getPhoneNumbers(); //this also return String int i = Integer.parseInt(str); – Masresha Seyoum Sep 11 '18 at 13:57