作为服务机器人发送短信 [英] Sending sms in android as a service

查看:138
本文介绍了作为服务机器人发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个应用程序,它可以让我们自动发送短信到我们的接触,即用户界面使我们能够将其送我们到的时间和短信内容。现在我该怎样检查是否是时候发送短信,即使在应用程序关闭。

我觉得服务是用于论文的任务?

解决方案

 私人无效setRecurringAlarm(上下文的背景下){

    日历更新时间= Calendar.getInstance();
    updateTime.setTimeZone(TimeZone.getTimeZone(GMT));
    updateTime.set(Calendar.HOUR_OF_DAY,11);
    updateTime.set(Calendar.MINUTE,45);

    意图下载=新的意图(背景下,AlarmReceiver.class);
    PendingIntent recurringDownload = PendingIntent.getBroadcast(背景下,0,下载,PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager报警=(AlarmManager)getActivity()。getSystemService(
            Context.ALARM_SERVICE);
    alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP,
            updateTime.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY,recurringDownload);
}
 

这Alaram经理将调用AlarmReciever在预定的时间。这样来做。

您可以在这里找到更多的细节:调度任务

问候, Aqif哈米德

I am making an application which allows us to send sms to our contacts automatically, i.e the user interface allows us to insert the time and sms content which we have to send. Now how do I check that it is time to send sms even if the application is closed.

I think services are used for theses tasks?

解决方案

private void setRecurringAlarm(Context context) {

    Calendar updateTime = Calendar.getInstance();
    updateTime.setTimeZone(TimeZone.getTimeZone("GMT"));
    updateTime.set(Calendar.HOUR_OF_DAY, 11);
    updateTime.set(Calendar.MINUTE, 45);

    Intent downloader = new Intent(context, AlarmReceiver.class);
    PendingIntent recurringDownload = PendingIntent.getBroadcast(context, 0, downloader, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager alarms = (AlarmManager) getActivity().getSystemService(
            Context.ALARM_SERVICE);
    alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP,
            updateTime.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY, recurringDownload);
}

This Alaram Manager will invoke AlarmReciever at scheduled time. Do it this way.

You can find more details here: Scheduling Task

regards, Aqif Hamid

这篇关于作为服务机器人发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆