警报:调用状态栏通知活动不起作用

时间:2013-03-19 07:57:16

标签: android

 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在单独运行时工作正常,但不会从警报类中获取。

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

0 个答案:

没有答案