【问题标题】:sending SMS in an Android app [duplicate]在 Android 应用中发送短信 [重复]
【发布时间】:2017-04-15 14:04:18
【问题描述】:

您好,我正在开发一个应用程序,该应用程序通过单击按钮将人的位置通过 SMS 发送到他们选择的电话号码。我没有什么经验,并且已经研究过使用 Twilio API。有谁知道这是否可行,或者有其他方法可以解决这个问题吗?获取位置已涵盖我只是在查看如何通过单击按钮将其发送到电话号码。谢谢

【问题讨论】:

  • 直接从设备发送怎么样? Send SMS in android
  • 请注意标记,这个问题是关于Android编程的,不是 Android Studio。

标签: java android sms twilio twilio-api


【解决方案1】:

因此,据我所知,您实际上并不需要第三方将 SMS 从 Android 发送到预定义的电话号码。

请查看此帖子,解决问题的地方:Send SMS in android

为了便于使用,您可以使用/检查此功能,该功能适用​​于我的项目: *注意:这是用于向多个电话号码发送短信(因此是 for 循环)

private void MultipleSMS(String phoneNumber, final String message) {
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";

PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(
    SENT), 0);

PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
    new Intent(DELIVERED), 0);
 // ---when the SMS has been sent---


registerReceiver(new BroadcastReceiver() {

@Override
public void onReceive(Context arg0, Intent arg1) {

    switch (getResultCode()) {

        case Activity.RESULT_OK:

            ContentValues values = new ContentValues();

            for (int i = 0; i < MobNumber.size() - 1; i++) {
                values.put("address", MobNumber.get(i).toString());
                // txtPhoneNo.getText().toString());
                values.put("body", message.toString());
            }
            getContentResolver().insert(
                    Uri.parse("content://sms/sent"), values);
            Toast.makeText(getBaseContext(), "SMS sent",
                    Toast.LENGTH_SHORT).show();

            doCall();


            break;
        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
            Toast.makeText(getBaseContext(), "Generic failure",
                    Toast.LENGTH_SHORT).show();
            break;
        case SmsManager.RESULT_ERROR_NO_SERVICE:
            Toast.makeText(getBaseContext(), "No service",
                    Toast.LENGTH_SHORT).show();
            break;
        case SmsManager.RESULT_ERROR_NULL_PDU:
            Toast.makeText(getBaseContext(), "Null PDU",
                    Toast.LENGTH_SHORT).show();
            break;
        case SmsManager.RESULT_ERROR_RADIO_OFF:
            Toast.makeText(getBaseContext(), "Radio off",
                    Toast.LENGTH_SHORT).show();
            break;
    }
}
}, new IntentFilter(SENT));

// ---when the SMS has been delivered---
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
    switch (getResultCode()) {
        case Activity.RESULT_OK:
            Toast.makeText(getBaseContext(), "SMS delivered",
                    Toast.LENGTH_SHORT).show();
            break;
        case Activity.RESULT_CANCELED:
            Toast.makeText(getBaseContext(), "SMS not delivered",
                    Toast.LENGTH_SHORT).show();
            break;
    }
 }
}, new IntentFilter(DELIVERED));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-04
    • 2012-02-18
    • 2011-02-23
    • 1970-01-01
    • 2016-03-15
    • 2012-05-04
    相关资源
    最近更新 更多