0
我创建了一个应用程序,根据地理坐标计算一天中特定的一组时间。它会在那些时间发出通知。 我已经使用重复闹钟通知日常(虽然时间每天改变,因此不准确)。 但它没有通知我3天后(我没有观察到确切的天数),除非重置。为什么这样? 现在我已决定使用服务,将每天设置通知,因此准确。我如何编写服务并调用它?Android重复报警或服务?
public void alarmNoon(long diff) {
Intent intent = new Intent(this, PNoon.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
intent, PendingIntent.FLAG_CANCEL_CURRENT);
if (checkadan(1)==true){
if (diff>=0){
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+diff,
(1000*60*60*24), pendingIntent);}else{
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+diff+(1000*60*60*24), (1000*60*60*24), pendingIntent);
}}else{
am.cancel(pendingIntent);
}
}
差异是时间differnce btwn中午和当前时间
public class PNoon extends BroadcastReceiver {
Dialog db;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
Notification notification = new Notification(R.drawable.icon, "Time", System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
notification.setLatestEventInfo(context, "Time", "Its Noon", contentIntent);
notification.flags=Notification.FLAG_AUTO_CANCEL;
notification.sound=Uri.parse("android.resource://net.ttct.time/"+R.raw.NoonAnnouncement);
mNotificationManager.notify(1, notification);
}
}
而且声音停止,一旦通知栏拖动打开,应立即停止,只有当项目在通知栏被触摸。
<receiver android:process=":remote" android:name="PNoon"></receiver>
你看过http://developer.android.com/guide/topics/fundamentals/services.html广播吗? – THelper 2011-12-22 09:19:33
发布你的代码(你如何安排警报),不要忘记你的清单声明广播接收机 – 2011-12-22 09:27:21
我希望情况很清楚。警报每天在黎明,中午和黄昏设置通知。我应该实施本地服务还是远程信使服务?什么是差异? – JaseemAmeer 2011-12-25 07:34:05