public class MainActivity extends Activity {
Button b;
//FrameLayout fl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=(Button)findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent contactpicker=new Intent(Intent.ACTION_PICK,Contacts.CONTENT_URI);
startActivityForResult(contactpicker, 0);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (resultCode == RESULT_OK) {
switch (requestCode) {
case 0:
Uri contactUri = data.getData();
FrameLayout badgeLargeHolder = (FrameLayout)
findViewById(R.id.badge_holder_large);
QuickContactBadge badgeLarge = new QuickContactBadge(this);
badgeLarge.assignContactUri(contactUri);
badgeLarge.setMode(ContactsContract.QuickContact.MODE_LARGE);
badgeLarge.setImageResource(R.drawable.ic_launcher);
badgeLargeHolder.addView(badgeLarge);
break;
}
}
}
}
我得到了这样的错误: 12-18 07:30:47.452:E / AndroidRuntime(657):android.content.ActivityNotFoundException:找不到处理Intent的活动{act = android.intent.action.PICK dat = content:// contacts}
提出解决此错误的建议。
答案 0 :(得分:1)
使用ContactsContract.Contacts.CONTENT_URI
代替Contacts.CONTENT_URI
Intent contactpicker = new Intent(Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(contactpicker, 0);
并在AndroidManifest.xml
<uses-permission android:name="android.permission.READ_CONTACTS" />