Commit dbd81883 authored by Sajal Narang's avatar Sajal Narang

Fix app crash on NotificationEventReceiver (possibly)

parent c0443f6c
...@@ -2,6 +2,7 @@ package app.insti.notifications; ...@@ -2,6 +2,7 @@ package app.insti.notifications;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver; import android.support.v4.content.WakefulBroadcastReceiver;
...@@ -10,8 +11,9 @@ import android.util.Log; ...@@ -10,8 +11,9 @@ import android.util.Log;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
public class import static android.support.v4.content.ContextCompat.startForegroundService;
NotificationEventReceiver extends WakefulBroadcastReceiver {
public class NotificationEventReceiver extends BroadcastReceiver {
private static final String ACTION_START_NOTIFICATION_SERVICE = "ACTION_START_NOTIFICATION_SERVICE"; private static final String ACTION_START_NOTIFICATION_SERVICE = "ACTION_START_NOTIFICATION_SERVICE";
private static final String ACTION_DELETE_NOTIFICATION = "ACTION_DELETE_NOTIFICATION"; private static final String ACTION_DELETE_NOTIFICATION = "ACTION_DELETE_NOTIFICATION";
...@@ -57,7 +59,7 @@ NotificationEventReceiver extends WakefulBroadcastReceiver { ...@@ -57,7 +59,7 @@ NotificationEventReceiver extends WakefulBroadcastReceiver {
} }
if (serviceIntent != null) { if (serviceIntent != null) {
startWakefulService(context, serviceIntent); startForegroundService(context, serviceIntent);
} }
} }
} }
\ No newline at end of file
...@@ -9,7 +9,6 @@ import android.content.Intent; ...@@ -9,7 +9,6 @@ import android.content.Intent;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log; import android.util.Log;
import java.util.Date; import java.util.Date;
...@@ -62,7 +61,6 @@ public class NotificationIntentService extends IntentService { ...@@ -62,7 +61,6 @@ public class NotificationIntentService extends IntentService {
@Override @Override
protected void onHandleIntent(Intent intent) { protected void onHandleIntent(Intent intent) {
Log.d(getClass().getSimpleName(), "onHandleIntent, started handling a notification event"); Log.d(getClass().getSimpleName(), "onHandleIntent, started handling a notification event");
try {
String action = intent.getAction(); String action = intent.getAction();
if (ACTION_START.equals(action)) { if (ACTION_START.equals(action)) {
processStartNotification(); processStartNotification();
...@@ -98,9 +96,6 @@ public class NotificationIntentService extends IntentService { ...@@ -98,9 +96,6 @@ public class NotificationIntentService extends IntentService {
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri); Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
startActivity(mapIntent); startActivity(mapIntent);
} }
} finally {
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
} }
private void processDeleteNotification(Intent intent) { private void processDeleteNotification(Intent intent) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment