Android 无法调用对话框下的内置SMS方法

Android 无法调用对话框下的内置SMS方法,android,Android,在点击“是”对话框后,我正在尝试使用内置的SMS。我从通讯录中找到了联系人 public class ContactListActivity extends Activity implements OnItemClickListener { private ListView listView; private List<ContactBean> list = new ArrayList<ContactBean>(); @Override protected

在点击“是”对话框后,我正在尝试使用内置的SMS。我从通讯录中找到了联系人

public class ContactListActivity extends Activity implements
      OnItemClickListener {
private ListView listView;
private List<ContactBean> list = new ArrayList<ContactBean>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    listView = (ListView) findViewById(R.id.list);
    listView.setOnItemClickListener(this);

    Cursor phones = getContentResolver().query(
            ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
            null, null);
    while (phones.moveToNext()) {

        String name = phones
                .getString(phones
                        .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));

        String phoneNumber = phones
                .getString(phones
                        .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

        ContactBean objContact = new ContactBean();
        objContact.setName(name);
        objContact.setPhoneNo(phoneNumber);
        list.add(objContact);

    }
    phones.close();

    ContanctAdapter objAdapter = new ContanctAdapter(
            ContactListActivity.this, R.layout.alluser_row, list);
    listView.setAdapter(objAdapter);

    if (null != list && list.size() != 0) {
        Collections.sort(list, new Comparator<ContactBean>() {

            @Override
            public int compare(ContactBean lhs, ContactBean rhs) {
                return lhs.getName().compareTo(rhs.getName());
            }
        });
        AlertDialog alert = new AlertDialog.Builder(
                ContactListActivity.this).create();
        alert.setTitle("");

        alert.setMessage(list.size() + " Contact Found!!!");

        alert.setButton("OK", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        alert.show();

    } else {
        showToast("No Contact Found!!!");
    }
}

private void showToast(String msg) {
    Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}

@Override
public void onItemClick(AdapterView<?> listview, View v, int position,
        long id) {
    ContactBean bean = (ContactBean) listview.getItemAtPosition(position);
    showCallDialog(bean.getName(), bean.getPhoneNo());
}

private void showCallDialog(String name, final String phoneNo) {
    AlertDialog alert = new AlertDialog.Builder(ContactListActivity.this)
            .create();
    alert.setTitle("Find?");

    alert.setMessage("Are you sure want to find " + name + " ?");

    alert.setButton("No", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    alert.setButton2("Yes", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
                sendSMS(phoneNo, "Where are you?");
        }
    });
    alert.show();
}

private void sendSMS(String phoneNumber, String message){
    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber, null, message, null, null);
}
}