gpt4 book ai didi

安卓通知时间

转载 作者:搜寻专家 更新时间:2023-11-01 08:14:34 26 4
gpt4 key购买 nike

我有一个公共(public)类来发出通知......

public class notifyHelper  {
public void sendNotification(Activity caller, Class<?> activityToLaunch, String title, String msg, int numberOfEvents, boolean flashLed, boolean vibrate, int ID) {
NotificationManager notifier = (NotificationManager) caller.getSystemService(Context.NOTIFICATION_SERVICE);

// Create this outside the button so we can increment the number drawn over the notification icon.
// This indicates the number of alerts for this event.
long whenTo = System.currentTimeMillis() + (1000 * 60 * 15);
final Notification notify = new Notification(R.drawable.icon, "", whenTo);

notify.icon = R.drawable.icon;
notify.tickerText = "TV Spored ++";
notify.when = whenTo;
notify.number = numberOfEvents;
notify.flags |= Notification.FLAG_AUTO_CANCEL;

if (flashLed) {
// add lights
notify.flags |= Notification.FLAG_SHOW_LIGHTS;
notify.ledARGB = Color.CYAN;
notify.ledOnMS = 500;
notify.ledOffMS = 500;
notify.defaults |= Notification.DEFAULT_SOUND;
}

if (vibrate) {

notify.vibrate = new long[] {100, 200, 200, 200, 200, 200, 1000, 200, 200, 200, 1000, 200};
}

Intent toLaunch = new Intent(caller, activityToLaunch);
PendingIntent intentBack = PendingIntent.getActivity(caller, 0, toLaunch, 0);

notify.setLatestEventInfo(caller, title, msg, intentBack);
notifier.notify(ID, notify);
}

public static void clear(Activity caller) {
NotificationManager notifier = (NotificationManager) caller.getSystemService(Context.NOTIFICATION_SERVICE);
notifier.cancelAll();
}
}

无论我做什么(看看什么时候),这个通知总是在调用时显示...我如何设置通知时间?

感谢您的回答!

最佳答案

是什么让您认为有一种方法可以创建非即时通知?

来自 http://developer.android.com/reference/android/app/Notification.html你可以看到一些重要的事情。首先,您正在使用的构造函数已被弃用——您应该考虑使用 http://developer.android.com/reference/android/app/Notification.Builder.html反而。但更重要的是,第三个参数不是“何时显示通知”,而是在通知本身的时间字段中显示的时间。想象一下……调用你的电话,不要接听(为了引起未接来电通知)。然后拉下通知抽屉,注意右下角显示的时间。

关于安卓通知时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6138688/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com