gpt4 book ai didi

android - 在 android 中标记问题

转载 作者:行者123 更新时间:2023-11-30 04:06:28 25 4
gpt4 key购买 nike

我试图让我的通知在用户按下“全部清除”时不取消到目前为止,我的 Intent 是在除此之外的所有事情上正常工作:

        Intent intent = new Intent(getBaseContext(), MainActivity.class);
intent.addFlags(Notification.FLAG_ONGOING_EVENT);
intent.addFlags(Notification.FLAG_NO_CLEAR);
PendingIntent contentIntent = PendingIntent.getActivity(
getBaseContext(), 0, intent, 0);

此时我的问题是:我的标志是否正确?

最佳答案

是的,你的标志看起来非常正确,虽然我不知道你是否甚至需要 FLAG_NO_CLEAR。我目前有一个创建持续(不可取消)通知的应用程序 - 我只使用 FLAG_ONGOING_EVENT 并且它对我来说工作正常。我几乎只是从教程中复制它,然后添加了正在进行的事件标志。下面是一些示例代码:

String text = "notification";
Notification notification = new Notification(R.drawable.icon, text,
System.currentTimeMillis());

//launch the activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent().setComponent(ComponentName.unflattenFromString("com.example/com.example.MyActivity")), 0);

// set the label and text...
notification.setLatestEventInfo(this, getText(R.string.notification_label),
text, contentIntent);
notification.flags = Notification.FLAG_ONGOING_EVENT;

// Send the notification.
// We use a string id because it is a unique number. We use it later to cancel.
NotificationManager mNM;
mNM.notify(R.string.notification_label, notification);

关于android - 在 android 中标记问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11563698/

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