android延迟通知,立即工作

时间:2012-04-21 14:17:29

标签: android android-intent notifications

下面是我在内部使用的代码和onClickListener,我想显示通知,一段时间后说30秒,但会立即显示。

        String title = "sample title"
        String text = "sample text";

        Calendar target = Calendar.getInstance();
        target.set( Calendar.HOUR_OF_DAY, model.getAlarmHour() );
        target.set( Calendar.MINUTE, model.getAlarmMinute() );
        target.set( Calendar.SECOND, 0 );

        int icon = android.R.drawable.stat_notify_error;

        String ns = context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);

        Intent notificationIntent = new Intent( context, WakeUpNotify.class );
        PendingIntent contentIntent = PendingIntent.getActivity( context, 0, notificationIntent, 0);

        Notification notification = new Notification(icon, text, target.getTimeInMillis() );
        notification.setLatestEventInfo(appContext, title, text, contentIntent);

        mNotificationManager.notify( notifyId, notification );

1 个答案:

答案 0 :(得分:0)

显示target时,Notification无法控制。它仅确定此项目的通知抽屉条目中显示的时间。