2011-04-26 104 views
0

我想從我的應用程序活動啓動聯繫人應用程序。我無法理解如何去做。Android啓動聯繫人應用程序

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); 
     } 
    }); 

錯誤:

enter image description here

回答

10
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); 
} 

這應該適用於從甜甜圈到薑餅的所有事情:不清楚Honeycomb。

+0

非常感謝好友。工作:) – 2011-04-26 08:42:08

1

可以啓動聯繫人選取器:

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

或者你也可以啓動應用程序:

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

+0

我想啓動的應用程序不是我使用2.2版本,聯繫人選取器 – 2011-04-26 07:15:30

+0

被斬首 – 2011-04-26 07:50:50

+0

看到ContactsContract:http://developer.android.com/reference/android/provider/ContactsContract.html – 2011-04-26 09:56:20

相關問題