Android 在安卓系统中发送短信,

Android 在安卓系统中发送短信,,android,Android,我已经实现了向多个用户发送消息。 下面是我想进一步做的 我在我的主要活动上点击按钮安卓的默认联系人簿应该打开 当我点击电话簿中的特定联系人时 那个电话号码是多少 选定的联系人应出现在 我的主要活动是编辑框 我已经调用了像这样的按钮点击事件的意图 addcontact.setOnClickListener(new View.OnClickListener() { public void onClick(View V) { Intent ContactPickerInten

我已经实现了向多个用户发送消息。 下面是我想进一步做的

  • 我在我的主要活动上点击按钮安卓的默认联系人簿应该打开
  • 当我点击电话簿中的特定联系人时 那个电话号码是多少 选定的联系人应出现在 我的主要活动是编辑框
  • 我已经调用了像这样的按钮点击事件的意图

    addcontact.setOnClickListener(new View.OnClickListener() {
    
        public void onClick(View V) {
            Intent ContactPickerIntent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
            startActivityForResult(ContactPickerIntent, CONTACT_PICKER_RESULT);             
        }
    });
    

    现在我陷入了如何从OnActivity结果中检索电话号码的困境。

    这应该可以工作,尽管我还没有测试过它:

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Cursor cursor = null;
        String number = "";
        Uri result = data.getData();
    
        // get the contact id from the Uri
        String id = result.getLastPathSegment();
    
        Cursor phones = getContentResolver().query(Phone.CONTENT_URI, null,
        Phone.CONTACT_ID + " = " + id, null, null);
        while (phones.moveToNext()) {
            String number = phones.getString(phones.getColumnIndex(Phone.NUMBER));
            int type = phones.getInt(phones.getColumnIndex(Phone.TYPE));
            switch (type) {
            case Phone.TYPE_HOME:
                // do something with the Home number here...
                break;
            case Phone.TYPE_MOBILE:
                // do something with the Mobile number here...
                break;
            case Phone.TYPE_WORK:
                // do something with the Work number here...
                break;
            }
        }
        phones.close();
    }
    
    您需要使用onAcitivtyResult和a来获取数字。 您可能还希望通过以下方式检查返回的结果是否来自ContactPickerEvent,而不是其他活动:

    switch (requestCode) 
            case CONTACT_PICKER_RESULT:
    

    我已经找到了解决办法。。。谢谢你的努力。。。我想补充一点,如果我们像这样使用,那么它将在版本2.0,2.2上工作,但在1.6上不工作。。无论如何,谢谢你的努力