0

下面是我在内部和 onClickListner 中使用的代码,我想显示通知,一段时间后说 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 );
4

1 回答 1

0

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

于 2012-04-21T15:11:36.680 回答