我必须从我的Android应用程序每天结束时通过电子邮件发送报告。我如何计划任务每天执行一次?如果互联网不可用,则在互联网返回时发送报告。 请帮助我..在Android中:如何使Android应用程序每天发送报告或一天24小时发送报告
感谢提前..
我必须从我的Android应用程序每天结束时通过电子邮件发送报告。我如何计划任务每天执行一次?如果互联网不可用,则在互联网返回时发送报告。 请帮助我..在Android中:如何使Android应用程序每天发送报告或一天24小时发送报告
感谢提前..
你需要使用AlarmManager在特定peroid或不同intervals..set了广播接收器来触发报警器,以获得报警解雇....并启动意图服务发送的电子邮件在后台
的示例类接收报警在mainactivity:
public void setRepeatingAlarm()
{
Intent intent = new Intent(this, ReceiveAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
(10000 * 1000), pendingIntent);
}
广播接收机:
public class ReceiveAlarm extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
context.startService(new Intent(context, InService.class));
}
}
意向的服务类实例:
public class InService extends IntentService
{
public InService() {
super("InService");
// TODO Auto-generated constructor stub
}
@Override
protected void onHandleIntent(Intent intent) {
//send email here
}
}
声明你的广播接收器/服务类清单内标签
<receiver android:name="ReceiveAlarm" />
<service android:name="InService"></service>
日程表,肯定你必须看到AlarmManager http://developer.android.com/reference/android/app/AlarmManager.html。
你在Android的heared服务。
1.创建一个服务
2.使用报警管理,BroadCastReciever
用于例如,
service.setInexactRepeating(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(), REPEAT_TIME, pending);
3.Boot在平板电脑上切换动作
for例如,
Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())
这里是伟大的教程http://www.vogella.com/articles/AndroidServices/article.html这可能会帮助你