parent
1b63ed0b20
commit
e67ac95890
1 changed files with 8 additions and 15 deletions
|
@ -6,9 +6,11 @@ import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
|
import androidx.core.app.AlarmManagerCompat;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import org.signal.core.util.logging.Log;
|
import org.signal.core.util.logging.Log;
|
||||||
import org.whispersystems.signalservice.api.util.SleepTimer;
|
import org.whispersystems.signalservice.api.util.SleepTimer;
|
||||||
|
|
||||||
|
@ -66,23 +68,14 @@ public class AlarmSleepTimer implements SleepTimer {
|
||||||
private void setAlarm(long millis, String action) {
|
private void setAlarm(long millis, String action) {
|
||||||
final Intent intent = new Intent(action);
|
final Intent intent = new Intent(action);
|
||||||
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
|
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
|
||||||
final AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
|
final AlarmManager alarmManager = ContextCompat.getSystemService(context, AlarmManager.class);
|
||||||
|
|
||||||
Log.w(TAG, "Setting alarm to wake up in " + millis + "ms.");
|
Log.w(TAG, "Setting alarm to wake up in " + millis + "ms.");
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
AlarmManagerCompat.setExactAndAllowWhileIdle(alarmManager,
|
||||||
alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
||||||
SystemClock.elapsedRealtime() + millis,
|
SystemClock.elapsedRealtime() + millis,
|
||||||
pendingIntent);
|
pendingIntent);
|
||||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
||||||
alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
|
||||||
SystemClock.elapsedRealtime() + millis,
|
|
||||||
pendingIntent);
|
|
||||||
} else {
|
|
||||||
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
|
||||||
SystemClock.elapsedRealtime() + millis,
|
|
||||||
pendingIntent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue