遇到如下报错:
Fatal Exception: java.langlllegalArgumentException
: Targeting S+ (version 31 and above) reures that one of FLAG_MMUTABLE r FLA-MUTABLE be specfed when creating a Pendinglntent. Strongly consider using FLAG_JMMUTABLE only use FLAG_MUTABLE if some unctionalty depends on the Pendinglintent being mutable e.g, ifitneeds to be used with inline replies or bubles
关于PendingIntent
进行以下修改:
PendingIntent pendingIntent ;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getActivity(ControlActivity.this, 0, intent, PendingIntent.FLAG_IMMUTABLE);
}else {
pendingIntent = PendingIntent.getActivity(ControlActivity.this, 0, intent, 0);
}
PendingIntent alarmIntent; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { alarmIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_IMMUTABLE); } else { alarmIntent = PendingIntent.getBroadcast(this, 0, intent, 0); }