在Android的:如何使Android应用程序每天在一天结束时或24小时发送一次报告 [英] In android:how to make a android application to send the report daily at end of the day or 24 hours once

查看:731
本文介绍了在Android的:如何使Android应用程序每天在一天结束时或24小时发送一次报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要通过电子邮件每一天的结束从我的Andr​​oid应用程序发送的报告。我如何安排执行每天一次的任务。如果网络不可用时,互联网回来报告发送。
请帮助我..

I have to send report via email every end of the day from my android application . How can I schedule the task to execute once a day. If internet is unavailable the report send when internet comes back. Kindly help me..

提前感谢..

推荐答案

您需要使用AlarmManager在特定peroid或在不同intervals..set了广播接收器来触发报警器,以获得报警解雇....和启动意图服务发送的电子邮件的背景

you need to use AlarmManager to trigger alarm at specific peroid or at different intervals..set up a Broadcast Receiver to get the alarm fired....and start an intent service to send emails in the background

为例类接收main​​activity报警:

an example class to receive alarm in 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));
     }
}

意图服务类例如:

Intent service class example:

 public class InService extends IntentService
    {
        public InService() {
            super("InService");
            // TODO Auto-generated constructor stub
        }

    @Override
    protected void onHandleIntent(Intent intent) {

//send email here
}

}

您声明广播接收器/服务类清单中的标签内。

Declare your broadcast receiver / service class in manifest inside tags

<receiver android:name="ReceiveAlarm" />
<service android:name="InService"></service>

这篇关于在Android的:如何使Android应用程序每天在一天结束时或24小时发送一次报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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