Targeting S+ (version 31 and abo

2022-08-11  本文已影响0人  wenju

问题: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.

可按照下面流程分别处理测试:
1.含有待意图

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { 
            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, PendingIntent.getBroadcast(getApplicationContext(), 0, alertIntent, PendingIntent.FLAG_MUTABLE)); 
        } else { 
            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, PendingIntent.getBroadcast(getApplicationContext(), 0, alertIntent, PendingIntent.FLAG_UPDATE_CURRENT)); 
        }

2.将以下行添加到 build.gradle

implementation 'androidx.work:work-runtime:2.7.1'

3.添加权限

<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
上一篇下一篇

猜你喜欢

热点阅读