Open a contact from the android contacts application from my application by id

1

I'm starting on Android, and I need to open from my application the contact in particular of the native contacts application by passing the id, I get to open the android contacts application, but only the main page, and I can not find the form to do it, I'd like to do it from a button that calls the following method:

   public void vercontacto(View view) {
        Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
        startActivity(contactPickerIntent);
    }

Logically, changing what I have in the right way to do it, the id is declared at the beginning of the class and initialized in the onCreate method, how could I do it? Greetings and thanks in advance.

    
asked by Coches Opinion 22.07.2017 в 16:07
source

1 answer

0

If you wish to open the application only, you can do it in this way, using the application package:

public void showContactsApp(){

    Intent intent  = new Intent();
    intent.setComponent(new ComponentName("com.android.contacts", "com.android.contacts.DialtactsContactsEntryActivity"));
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    intent.addCategory("android.intent.category.DEFAULT");
    startActivity(intent);

}

If what you want is to open the information of a specific contact by its ID, it is done in the following way:

public void openContactById(int contactID){

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactID));
    intent.setData(uri);
    startActivity(intent);

}
    
answered by 22.07.2017 / 23:10
source