错误日志 :
java.lang.IllegalArgumentException: com.example.notificationtest: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
解决:添加版本判断
val pendingFlags : Int = if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){
PendingIntent.FLAG_IMMUTABLE
}else{
PendingIntent.FLAG_ONE_SHOT
}
val pi = PendingIntent.getActivity(this,0,intent, pendingFlags)

3080

被折叠的 条评论
为什么被折叠?



