美文网首页
Targeting S+ (version 31 and abo

Targeting S+ (version 31 and abo

作者: wenju | 来源:发表于2022-08-11 10:51 被阅读0次

    问题: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"/>
    

    相关文章

      网友评论

          本文标题:Targeting S+ (version 31 and abo

          本文链接:https://www.haomeiwen.com/subject/epizwrtx.html