如何从int数组中检索数据以拨打电话

时间:2013-09-03 05:44:13

标签: android android-intent

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

3 个答案:

答案 0 :(得分: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" />

答案 1 :(得分: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" />

答案 2 :(得分: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;
}