定位 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/