|
@@ -13,14 +13,21 @@ class SendService : IntentService("SendService") {
|
|
|
|
|
|
companion object {
|
|
|
val ACTION_SEND = "com.pleasantprogrammer.mpp.action.SEND"
|
|
|
+ val ACTION_BOOT = "com.pleasantprogrammer.mpp.action.BOOT"
|
|
|
|
|
|
val INTERVAL = 60 * 1000L
|
|
|
|
|
|
- fun makeIntent(ctx: Context): Intent {
|
|
|
+ fun makeSendIntent(ctx: Context): Intent {
|
|
|
val intent = Intent(ACTION_SEND)
|
|
|
intent.setClass(ctx, SendService::class.java)
|
|
|
return intent
|
|
|
}
|
|
|
+
|
|
|
+ fun makeBootIntent(ctx: Context): Intent {
|
|
|
+ val intent = Intent(ACTION_BOOT)
|
|
|
+ intent.setClass(ctx, SendService::class.java)
|
|
|
+ return intent
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
val sharedPreferences: SharedPreferences by lazy {
|
|
@@ -35,6 +42,10 @@ class SendService : IntentService("SendService") {
|
|
|
sharedPreferences.edit().putLong("last_requested", System.currentTimeMillis()).commit()
|
|
|
scheduleNext()
|
|
|
}
|
|
|
+ else if(intent.action == ACTION_BOOT) {
|
|
|
+ Log.i("SendService", "Rescheduling because of restart")
|
|
|
+ scheduleNext()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
fun scheduleNext() {
|
|
@@ -42,7 +53,7 @@ class SendService : IntentService("SendService") {
|
|
|
if(from < 0) return
|
|
|
|
|
|
val pendingIntent = PendingIntent.getService(
|
|
|
- this, 0, makeIntent(this), PendingIntent.FLAG_ONE_SHOT
|
|
|
+ this, 0, makeSendIntent(this), PendingIntent.FLAG_ONE_SHOT
|
|
|
)
|
|
|
|
|
|
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
|