我在以10秒interval.I状态栏通知的问题已通过创建代码做了显示其一次性plugin.But我想在每10分钟来显示它interval.So我使用AlarmManager
每10分钟产生一次通知。但它不叫onReceive(Context ctx, Intent intent)
类的FirstQuoteAlarm
类。 我有以下代码显示通知和AlarmManager
。状态栏通知
public void showNotification(CharSequence contentTitle, CharSequence contentText) {
int icon = R.drawable.nofication;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, contentTitle, when);
Intent notificationIntent = new Intent(ctx, ctx.getClass());
PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(1, notification);
Date dt = new Date();
Date newdate = new Date(dt.getYear(), dt.getMonth(), dt.getDate(),10,14,dt.getSeconds());
long triggerAtTime = newdate.getTime();
long repeat_alarm_every = 1000;
QuotesSetting.ON = 1;
AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
//Intent intent = new Intent("REFRESH_ALARM");
Intent intent1 = new Intent(ctx,FirstQuoteAlarm.class);
PendingIntent pi = PendingIntent.getBroadcast(ctx, 0, intent1, 0);
am.setRepeating(AlarmManager.RTC_WAKEUP, triggerAtTime, repeat_alarm_every, pi);
Log.i("call2","msg");
}
为什么你会每10分钟更新一次?这是非常不友好的电池 – Dediqated 2013-06-07 11:18:24