通过Android设备发送短信失败

时间:2013-03-01 07:20:39

标签: android

我正在编写一个应用程序,我正在尝试向收件人发送短信,但每当我点击发送,收到消息: - 短信,请稍后再试!

要么我使用模拟器或Android设备......

就像你可以在下面的屏幕截图中看到的,这里我正在尝试向Pratik发送消息,该消息保存在我的电话簿联系人中,但每当我试图向Pratik发送消息时无法向Pratik发送消息

请看下面的屏幕截图,就像你可以看到的,这里我正在尝试向Rahul发送消息......

的Manifest.xml:

<uses-permission android:name="android.permission.SEND_SMS" />

请检查以下代码:

    private TextView name;
private ListView list;
private Database db;
private Contact contact;
ImageButton buttonSend;
EditText textSMS;

     protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.editor);

    // bind GUI components
    this.name = (TextView) findViewById(R.id.editor_name);
    this.list = (ListView) findViewById(R.id.editor_list);

    // check if contact id is valid
    this.db = new Database(getContentResolver());
    int contactId = getIntent().getIntExtra(CONTACT_ID, NO_CONTACT_ID);
    this.contact = this.db.getContact(contactId);
    if (this.contact == null) {
        finish();
    }
    this.name.setText(this.contact.getName());

    // pre-load information about all account types
    AuthenticatorDescription[] authTypes = AccountManager.get(this).getAuthenticatorTypes();
    for (AuthenticatorDescription authDesc : authTypes) {
        this.map.put(authDesc.type, authDesc);
    }

    // bind list events
    this.list.setOnItemClickListener(this);
    this.list.setOnCreateContextMenuListener(this);

    // create the GUI
    updateView();


    saveGreeting = (ImageButton) findViewById(R.id.greeting);
    saveGreeting.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            customGreeting(v);
        }
    });
    buttonSend = (ImageButton) findViewById(R.id.buttonSend);
    textSMS = (EditText) findViewById(R.id.editTextSMS);
    buttonSend.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

          String sms = textSMS.getText().toString();

          try {
            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(CONTACT_ID, null, sms, null, null);
            Toast.makeText(getApplicationContext(), "SMS Sent!",
                        Toast.LENGTH_LONG).show();
          } catch (Exception e) {
            Toast.makeText(getApplicationContext(),
                "SMS faild, please try again later!",
                Toast.LENGTH_LONG).show();
            e.printStackTrace();
          }

        }
    });
}

1 个答案:

答案 0 :(得分:2)

请勿使用收件人姓名发送邮件,请使用手机号码发送邮件。

从联系人列表中获取联系电话,并在sendTextMessage函数中使用该联系号码而不是名称。