Skip to content

Commit

Permalink
v6.11: Fixed deprecated usage of broadcast receivers causing wrong wo…
Browse files Browse the repository at this point in the history
…rk on Android 14
  • Loading branch information
vmayorow committed Nov 10, 2024
1 parent 976292f commit 8af459a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ android {
applicationId "com.hmdm.launcher"
minSdkVersion 16
targetSdkVersion 34
versionCode 15100
versionName "6.10"
versionCode 15110
versionName "6.11"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
dataBinding {
enabled = true
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/hmdm/launcher/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,11 @@ public void uncaughtException(Thread t, Throwable e) {
intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
intentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(stateChangeReceiver, intentFilter);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
registerReceiver(stateChangeReceiver, intentFilter, Context.RECEIVER_EXPORTED);
} else {
registerReceiver(stateChangeReceiver, intentFilter);
}

if (!getIntent().getBooleanExtra(Const.RESTORED_ACTIVITY, false)) {
startAppsAtBoot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ public static DeviceInfo getDeviceInfo(Context context, boolean queryPermissions
// Battery
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);

Intent batteryStatus = context.registerReceiver(null, ifilter);
Intent batteryStatus = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ?
context.registerReceiver(null, ifilter, Context.RECEIVER_EXPORTED) :
context.registerReceiver(null, ifilter);
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
if (status == BatteryManager.BATTERY_STATUS_CHARGING ||
status == BatteryManager.BATTERY_STATUS_FULL) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ 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));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
service.registerReceiver(alarmReceiver, new IntentFilter(action), Context.RECEIVER_NOT_EXPORTED);
} else {
service.registerReceiver(alarmReceiver, new IntentFilter(action));
}

pendingIntent = PendingIntent.getBroadcast(service, 0, new Intent(
action), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
Expand Down

0 comments on commit 8af459a

Please sign in to comment.