如何在Android中管理自定义通知

mgdq6dx1  于 2022-11-03  发布在  Android
关注(0)|答案(1)|浏览(147)

警告:字段需要API级别23(当前最低级别为21):android.app.PendingIntent#FLAG_IMMUTABLE

`

val pendingIntent = PendingIntent.getBroadcast(
    context, NOTIFICATION_ID,
    intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)

`
如何管理此警告?

tjjdgumg

tjjdgumg1#

可能性:

val flag = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE else PendingIntent.FLAG_UPDATE_CURRENT
 val pendingIntent = PendingIntent.getActivity(context, PENDING_INTENT_REQUEST_CODE, notificationIntent, flag)

相关问题