Permalink
Browse files

Send pings in Doze mode

This commit includes a bump to sdk 23 which brings setAndAllowWhileIdle
  • Loading branch information...
geekarist committed Jun 22, 2018
1 parent ce3f008 commit 4ac4bcafa21acae91884bc8db95be292105df88f
Showing with 21 additions and 7 deletions.
  1. +3 −3 src/and/tagTime/build.gradle
  2. +18 −4 src/and/tagTime/src/main/java/bsoule/tagtime/PingService.java
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 21
compileSdkVersion 23

defaultConfig {
applicationId "bsoule.tagtime"
minSdkVersion 8
targetSdkVersion 21
targetSdkVersion 23
}

buildTypes {
@@ -20,5 +20,5 @@ android {
dependencies {
compile project(':library')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:support-v4:23.4.0'
}
@@ -12,6 +12,7 @@
import android.net.Uri;
import android.os.BatteryManager;
import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.os.Parcel;
import android.os.PowerManager;
@@ -161,22 +162,25 @@ public void sendNote(long pingtime, long rowID) {
Date ping = new Date(pingtime * 1000);
CharSequence text = getText(R.string.status_bar_notes_ping_msg);

PendingIntent contentIntent = createPendingIntent(rowID, null);

// Set the icon, scrolling text, and timestamp.
NotificationCompat.Builder noteBuilder =
new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.stat_ping)
.setTicker(text)
.setContentTitle("Ping!")
.setContentText(SDF.format(ping))
.setContentIntent(contentIntent)
.setWhen(ping.getTime());

addTagActions(noteBuilder, rowID);

PendingIntent contentIntent = createPendingIntent(rowID, null);

// Set the info for the views that show in the notification panel.
// note.setLatestEventInfo(context, contentTitle, contentText,
// contentIntent)

Notification note = noteBuilder.build();
note.setLatestEventInfo(this, "Ping!", SDF.format(ping), contentIntent);

boolean suppress_noises = false;
if (mPrefs.getBoolean("pingQuietCharging", false)) {
@@ -287,7 +291,17 @@ private void setAlarm(long PING) {
AlarmManager alarum = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent alit = new Intent(this, TPStartUp.class);
alit.putExtra("ThisIntentIsTPStartUpClass", true);
alarum.set(AlarmManager.RTC_WAKEUP, PING * 1000, PendingIntent.getBroadcast(this, 0, alit, 0));

assert alarum != null;
int type = AlarmManager.RTC_WAKEUP;
long trigger = PING * 1000;
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alit, 0);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarum.setAndAllowWhileIdle(type, trigger, pendingIntent);
} else {
alarum.set(type, trigger, pendingIntent);
}
}

private static final long IA = 16807;

0 comments on commit 4ac4bca

Please sign in to comment.