Reset alarm on reboot and app upgrade
This commit is contained in:
parent
fbb4772132
commit
d0bfd7c02d
@ -23,7 +23,9 @@
|
|||||||
<uses-feature
|
<uses-feature
|
||||||
android:name="android.hardware.screen.portrait"
|
android:name="android.hardware.screen.portrait"
|
||||||
android:required="false" />
|
android:required="false" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name="de.danoeh.antennapod.PodcastApp"
|
android:name="de.danoeh.antennapod.PodcastApp"
|
||||||
@ -348,11 +350,23 @@
|
|||||||
android:configChanges="orientation"
|
android:configChanges="orientation"
|
||||||
android:label="@string/organize_queue_label" >
|
android:label="@string/organize_queue_label" >
|
||||||
</activity>
|
</activity>
|
||||||
<receiver android:name=".receiver.ConnectivityActionReceiver">
|
|
||||||
|
<receiver android:name=".receiver.ConnectivityActionReceiver" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
|
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
<receiver android:name=".receiver.AlarmUpdateReceiver" >
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.PACKAGE_REPLACED" />
|
||||||
|
<data
|
||||||
|
android:path="de.danoeh.antennapod"
|
||||||
|
android:scheme="package" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -198,11 +198,9 @@ public class UserPreferences implements
|
|||||||
followQueue = sp.getBoolean(PREF_FOLLOW_QUEUE, false);
|
followQueue = sp.getBoolean(PREF_FOLLOW_QUEUE, false);
|
||||||
|
|
||||||
} else if (key.equals(PREF_UPDATE_INTERVAL)) {
|
} else if (key.equals(PREF_UPDATE_INTERVAL)) {
|
||||||
int hours = Integer.parseInt(sp
|
updateInterval = readUpdateInterval(sp.getString(
|
||||||
.getString(PREF_UPDATE_INTERVAL, "0"));
|
PREF_UPDATE_INTERVAL, "0"));
|
||||||
updateInterval = readUpdateInterval(sp
|
restartUpdateAlarm(updateInterval);
|
||||||
.getString(PREF_UPDATE_INTERVAL, "0"));
|
|
||||||
restartUpdateAlarm(hours);
|
|
||||||
|
|
||||||
} else if (key.equals(PREF_AUTO_DELETE)) {
|
} else if (key.equals(PREF_AUTO_DELETE)) {
|
||||||
autoDelete = sp.getBoolean(PREF_AUTO_DELETE, false);
|
autoDelete = sp.getBoolean(PREF_AUTO_DELETE, false);
|
||||||
@ -347,20 +345,23 @@ public class UserPreferences implements
|
|||||||
/**
|
/**
|
||||||
* Updates alarm registered with the AlarmManager service or deactivates it.
|
* Updates alarm registered with the AlarmManager service or deactivates it.
|
||||||
*
|
*
|
||||||
* @param hours
|
* @param millis
|
||||||
* new value to register with AlarmManager. If hours is 0, the
|
* new value to register with AlarmManager. If millis is 0, the
|
||||||
* alarm is deactivated.
|
* alarm is deactivated.
|
||||||
* */
|
* */
|
||||||
public void restartUpdateAlarm(int hours) {
|
public static void restartUpdateAlarm(long millis) {
|
||||||
AlarmManager alarmManager = (AlarmManager) context
|
instanceAvailable();
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Restarting update alarm. New value: " + millis);
|
||||||
|
AlarmManager alarmManager = (AlarmManager) instance.context
|
||||||
.getSystemService(Context.ALARM_SERVICE);
|
.getSystemService(Context.ALARM_SERVICE);
|
||||||
PendingIntent updateIntent = PendingIntent.getBroadcast(context, 0,
|
PendingIntent updateIntent = PendingIntent.getBroadcast(
|
||||||
new Intent(FeedUpdateReceiver.ACTION_REFRESH_FEEDS), 0);
|
instance.context, 0, new Intent(
|
||||||
|
FeedUpdateReceiver.ACTION_REFRESH_FEEDS), 0);
|
||||||
alarmManager.cancel(updateIntent);
|
alarmManager.cancel(updateIntent);
|
||||||
if (hours != 0) {
|
if (millis != 0) {
|
||||||
long newIntervall = TimeUnit.HOURS.toMillis(hours);
|
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, millis, millis,
|
||||||
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, newIntervall,
|
updateIntent);
|
||||||
newIntervall, updateIntent);
|
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Changed alarm to new intervall");
|
Log.d(TAG, "Changed alarm to new intervall");
|
||||||
} else {
|
} else {
|
||||||
|
30
src/de/danoeh/antennapod/receiver/AlarmUpdateReceiver.java
Normal file
30
src/de/danoeh/antennapod/receiver/AlarmUpdateReceiver.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package de.danoeh.antennapod.receiver;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.AppConfig;
|
||||||
|
import de.danoeh.antennapod.preferences.UserPreferences;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
/** Listens for events that make it necessary to reset the update alarm. */
|
||||||
|
public class AlarmUpdateReceiver extends BroadcastReceiver {
|
||||||
|
private static final String TAG = "AlarmUpdateReceiver";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Received intent");
|
||||||
|
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Resetting update alarm after reboot");
|
||||||
|
} else if (intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Resetting update alarm after app upgrade");
|
||||||
|
}
|
||||||
|
|
||||||
|
UserPreferences.restartUpdateAlarm(UserPreferences.getUpdateInterval());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user