android - 在 android 中标记问题

标签 android flags

我试图让我的通知在用户按下“全部清除”时不取消到目前为止,我的 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/

相关文章:

Android 传感器 - 其中哪些获得直接输入?

javascript - React Native - 将函数的返回值设置为组件的属性不起作用

assembly - 关于汇编CF(进位)和OF(溢出)标志

binary - 在 COBOL 中与 Pic X 数据执行二进制 OR

java - ListAdapter 和 Fragment 之间的接口(interface)

android - ArrayList 不能转换为 Parcelable

android - 在 GPX 或 KML 中指定精度

Android: Intent 通过通知传递给 Activity ......我没有在 Intent 中获得正确的额外内容

重新定义了 Golang 标志

Python 和 GetVolumeInformationW 和 GetDriveTypeW : list all disks and get disk info and filesystem flags