Android Launching Contacts Application

懵懂的女人 提交于 2020-01-10 04:44:05

问题


I wanna launch the Contacts application from my application Activity. I am not able to understand how to do it.

    Button contact = (Button) findViewById(R.id.contact);
    contact.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            Intent i4 = new Intent();
            i4.setAction(Intent.ACTION_VIEW);
            i4.addCategory(Intent.CATEGORY_DEFAULT);
            i4.setType("vnd.android.cursor.dir/phone");
            startActivity(i4);
        }
    });

Error:


回答1:


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

This should work in everything from Donut through to Gingerbread: not sure about Honeycomb.




回答2:


You can launch a contact Picker:

public void doLaunchContactPicker(View view) {  
    Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,  
            Contacts.CONTENT_URI);  
    startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);  
}  

Or you can also launch the app:

http://developer.android.com/reference/android/provider/Contacts.Intents.html



来源:https://stackoverflow.com/questions/5787088/android-launching-contacts-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!