Use local broadcast receivers

This commit is contained in:
M66B
2023-09-21 08:45:04 +02:00
parent 875a959188
commit 199c5d8b14
4 changed files with 33 additions and 8 deletions

View File

@@ -212,22 +212,37 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
IntentFilter iif = new IntentFilter();
iif.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
iif.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
registerReceiver(connectionChangedReceiver, iif);
ContextCompat.registerReceiver(this,
connectionChangedReceiver,
iif,
ContextCompat.RECEIVER_NOT_EXPORTED);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
registerReceiver(idleModeChangedReceiver, new IntentFilter(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED));
ContextCompat.registerReceiver(this,
idleModeChangedReceiver,
new IntentFilter(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED),
ContextCompat.RECEIVER_NOT_EXPORTED);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
registerReceiver(dataSaverChanged, new IntentFilter(ConnectivityManager.ACTION_RESTRICT_BACKGROUND_CHANGED));
ContextCompat.registerReceiver(this,
dataSaverChanged,
new IntentFilter(ConnectivityManager.ACTION_RESTRICT_BACKGROUND_CHANGED),
ContextCompat.RECEIVER_NOT_EXPORTED);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
IntentFilter suspend = new IntentFilter();
suspend.addAction(Intent.ACTION_MY_PACKAGE_SUSPENDED);
suspend.addAction(Intent.ACTION_MY_PACKAGE_UNSUSPENDED);
registerReceiver(suspendChanged, suspend);
ContextCompat.registerReceiver(this,
suspendChanged,
suspend,
ContextCompat.RECEIVER_NOT_EXPORTED);
}
registerReceiver(batteryChanged, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
ContextCompat.registerReceiver(this,
batteryChanged,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED),
ContextCompat.RECEIVER_NOT_EXPORTED);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);