1
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: No Activity found to handle Intent { act=android.intent.action.PICK dat=content:/ /联系人}

提供解决此错误的任何建议。

4

1 回答 1

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" />
于 2012-12-18T02:37:57.543 回答