Android 12 待定意向

标签 android android-studio android-pendingintent

定位 S+(版本 31 及更高版本)要求在创建 PendingIntent 时指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一。强烈考虑使用 FLAG_IMMUTABLE,仅当某些功能依赖于 PendingIntent 可变时才使用 FLAG_MUTABLE
我无法在 android studio 项目编码中更新待处理的 Intent 标志
这是 AlarmPingSender.java 中发生错误的地方

  public void start()        
   {       
   String action = MqttServiceConstants.PING_SENDER
            + comms.getClient().getClientId();
    Log.d(TAG, "Register alarmreceiver to MqttService"+ action);
    service.registerReceiver(alarmReceiver, new IntentFilter(action));

    pendingIntent = PendingIntent.getBroadcast(service, 0, new Intent(
            action), PendingIntent.FLAG_UPDATE_CURRENT);

    schedule(comms.getKeepAlive());
    hasStarted = true;
}
帮我解决问题 ERROR IN ANDROID STUDIO IMAGE

最佳答案

你需要这样做:

pendingIntent = PendingIntent.getBroadcast(service, 0, new Intent(
        action), PendingIntent.FLAG_UPDATE_CURRENT |
                 PendingIntent.FLAG_IMMUTABLE);
由于您使用的是 AlarmManager您应该可以使用 IMMUTABLE旗帜。

关于Android 12 待定意向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70889493/

相关文章:

java - 当应用程序在前台运行时使用挂起 Intent 或其他解决方案从主菜单打开特定选项卡

android - 同一 Intent 的 Widget 上的多个 OnClick

android - Google 登录在发布版本上失败

javascript - 我可以从网站上唯一地识别移动设备吗?

java - 我如何每 10 秒显示一个字符串中的一个随机单词?

android - React Native, react-native run-android build 成功后自动关闭

java - 清除全局 ArrayList 也会清除另一个

java - 在 Android Studio 中的哪里添加类文件夹?

android - 在 Android Studio 中加载运行时库时出错

android - 如何在 Android Wear 中动态更改 Action 图标