短信未收到

时间:2016-11-19 12:09:19

标签: java android hyperlink sms smsmanager

我正在尝试将邮件发送到多个号码。但是消息没有被发送。我添加了代码以在服务中发送消息,以确保即使应用程序在后台也能执行代码。

我还在清单中添加了权限,并要求获得运行时权限。

消息服务:

public class MessageService extends Service {

    ArrayList<String>  numbers = new ArrayList<>();
    private SharedPreferences sharedpreferences;
    private String mUserName;

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        sharedpreferences = getSharedPreferences("UserProfile", Context.MODE_PRIVATE);

        mUserName = sharedpreferences.getString("UserUsername", "");

        numbers = intent.getStringArrayListExtra("numbers");

        for (String number:numbers) {

              sendMsg(number);

           // sendSMS("8655864341","Hello");
        }

        return super.onStartCommand(intent, flags, startId);
    }

    public void sendMsg(final String num){
        String SENT = "SMS_SENT";
        final SmsManager sms = SmsManager.getDefault();
        final PendingIntent sentPI = PendingIntent.getBroadcast(MessageService.this, 0,new Intent(SENT), 0);
        Handler h = new Handler();
        h.postDelayed(new Runnable() {
            @Override
            public void run() {
              //  sms.sendTextMessage(num, null, "Hi,I am " + mUserName + "add me to your unique contact list and you never need to update" +
                      //  " any changes anymore! Click download below to download the App." + "https://play.google.com/apps/testing/com.weberz", sentPI, null);

                sms.sendTextMessage(num, null, "Hi,add me to your unique contact list and you never need to update" +
                        " any changes anymore! Click download below to download the App.", sentPI, null);
            }
        }, 3000);


    }

}

这件事以前工作过,收到了关于号码的消息。现在我尝试在消息中添加链接和用户名,但它们没有被发送。

然后我再次尝试从邮件中删除链接和用户名,并检查邮件是否已发送且现在无法正常工作。

我还想知道如何在短信中添加超链接,以便用户在点击链接后可以打开网页?

2 个答案:

答案 0 :(得分:2)

由于您的短信提供商,您可能已被屏蔽。因为它们通常会阻止私人客户发送的链接以避免垃圾邮件。

在短信中添加超链接,只需将网址插入正常状态即可 串。就像你使用普通文本一样。大多数智能手机都会 解析链接并使其“可点击”,即使它在SMS中。 此外,考虑使用缩短URL的库 短信限制为160个字符。这是我正在使用的库:https://github.com/vekexasia/android-googl-shortener-lib

发送短信我建议使用:

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

此方法使用SmsManager,它非常易于使用(API 19)。欲获得更多信息:     https://developer.android.com/reference/android/telephony/SmsManager.html

答案 1 :(得分:1)

如果过去收到短信,但在尝试发送超级链接后无法使用,则可能是您使用的无线服务提供商已阻止您的SIM卡出现可疑的短信流量。带链接的邮件通常被视为垃圾邮件。

尝试更换SIM卡并再次发送“Hello World”消息。

手机识别短信中的超链接,大多数智能手机都可以点击。因此,只需将URL放在SMS中,收件人就可以单击它。它适用于iPhone和大多数Android手机。

相关问题