0

如何从 int 数组中获取号码以拨打电话?就像我得到了一个名称和数字的列表,所以当我单击 listview 项目时,它会调用存储在数组中该位置的数字

4

3 回答 3

0
 Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
            startActivityForResult(i, 1);
 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        String phoneNumber = getPhoneNumber(data.getData());
        if (phoneNumber.trim().length() > 0) {
            // use this phoneNumber 
        } else {
            ting("Phone Number Not Founded ...");
        }

    }
}
 // this method return only first mobile no selected contact.
 private String getPhoneNumber(Uri contactInfo) {
    String phoneNumbers = "";
    Cursor cursor = getContentResolver().query(contactInfo, null, null, null, null);
    while (cursor.moveToNext()) {
        String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
        String hashPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
        if ("1".equalsIgnoreCase(hashPhone)) {
            Cursor contactCursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null);
            while (contactCursor.moveToNext()) {
                int type = contactCursor.getInt(contactCursor.getColumnIndex(Phone.TYPE));
                if (type == Phone.TYPE_MOBILE) {
                    int colIdx = contactCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
                    phoneNumbers = phoneNumbers.concat(contactCursor.getString(colIdx));
                    break;
                }
            }
            contactCursor.close();
        }
    }
    cursor.close();
    return phoneNumbers;
}
于 2013-09-03T05:58:10.940 回答
0
  listview.setOnItemClickListener(new OnItemClickListener() {
    @Override
     public void onItemClick(AdapterView<?> parent, View view,int position, long id) 
        {
            Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:"+number)); //pass your telephone number
     startActivity(callIntent);

         }});

在清单中添加权限

   <uses-permission android:name="android.permission.CALL_PHONE" />
于 2013-09-03T05:52:46.790 回答
0

尝试这个

list.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {

            String name = ((TextView) view.findViewById(R.id.LR_Name)).getText().toString();
            String cost = ((TextView) view.findViewById(R.id.LR_date)).getText().toString();

            // Starting new intent
                Intent call = new Intent (Intent.ACTION_DIAL, Uri.parse("tel:" + lm.getPhone()));
                startActivity(call);
        }
    });

在清单中添加权限

   <uses-permission android:name="android.permission.CALL_PHONE" />
于 2013-09-03T05:49:47.943 回答