2013-09-05 44 views

回答

1

你需要使用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> 
0

你在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这可能会帮助你

相关问题