MyMQTT icon indicating copy to clipboard operation
MyMQTT copied to clipboard

AlarmPingSender only fires once

Open vleitch opened this issue 11 months ago • 1 comments

My app was only calling alarmpingsender() once on Android 14 device. (Works perfect pre 14). I assumed that my app was not receiving the alarm intent so I modified the start(0 function to have RECEIVER_EXPORTED instead of RECEIVER_NOT_EXPORTED. It now works as expected.

@Override public void start() { String action = MqttServiceConstants.PING_SENDER + comms.getClient().getClientId(); Log.d(TAG, "Register alarmreceiver to MqttService"+ action);

    // Fixed MQTT crash on Android 14
    // Must set targetSdkVersion 34 on build.gradle(:mqtt)
    // Android 14's new requirement for explicit RECEIVER_NOT_EXPORTED flags when registering broadcast receivers dynamically.
    IntentFilter filter = new IntentFilter(action);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
        service.registerReceiver(alarmReceiver, filter, Context.**RECEIVER_EXPORTED**);
    } else {
        service.registerReceiver(alarmReceiver, filter);
    }

vleitch avatar Mar 03 '25 17:03 vleitch