1
 private void scheduleAlarmReceiver() {
 AlarmManager alarmMgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
 PendingIntent pendingIntent =  PendingIntent.getBroadcast(this, 0, new Intent(this, StatusNotify.class),
 PendingIntent.FLAG_CANCEL_CURRENT);
 alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 2000,AlarmManager.INTERVAL_DAY, pendingIntent);
 Log.i("alarm", "alarm set");
 }

statusnotify.class

protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_status_notify);
 NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
 int unique_id = 145558;
 Log.i("status bar" +unique_id , " ");
 Intent nintent = new Intent();
 nintent.setClass(this, TaskTrace.class);
 PendingIntent pin = PendingIntent.getActivity(getApplicationContext(),0, nintent, 0);
 String title = "Notification";
 String body = "This is a new notification";
 Notification n = new Notification(R.drawable.ic_launcher, body, System.currentTimeMillis());
 n.contentIntent = pin;
 n.setLatestEventInfo(getApplicationContext(), title, body, pin);
 n.defaults = Notification.DEFAULT_ALL;
 nm.notify(unique_id, n);
 }

Statusnotify 在单独运行时工作正常,但不会从警报类中触发。

猜测意图调用中的一切都很好。请帮帮我。设置闹钟时,状态栏通知必须出现 1n 2 秒,并且每天在同一时间重复

4

0 回答 0