How to call Android contacts list AND Select one phone number from its details screen?

前端 未结 6 1231
余生分开走
余生分开走 2020-12-01 03:06

I have read the already posted solutions, but they dont tell how do I use system\'s contact details screen to select any ONE number to use? I am developing an sms sending an

6条回答
  •  长情又很酷
    2020-12-01 03:24

    this code just work fine with me

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
    
        Intent i = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
        super.startActivityForResult(i, 1001);
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
    
        switch (requestCode) {
        case 1001:
    
            if (resultCode == Activity.RESULT_OK) {
    
                Cursor s = getContentResolver().query(Phone.CONTENT_URI, null,
                        null, null, null);
    
            if (s.moveToFirst()) {
                    String phoneNum = s.getString(s.getColumnIndex(Phone.NUMBER));
                    Toast.makeText(getBaseContext(), phoneNum, Toast.LENGTH_LONG).show();
                                }
    
            }
    
            break;
    
        }
    
    }
    

提交回复
热议问题