Skip to content

Commit

Permalink
Android O and above bug related to starting service fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
thatsabhi22 committed May 8, 2020
1 parent ced81ec commit a04933b
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.udacity.bakingapp.widget;

import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;

import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;

import com.udacity.bakingapp.models.Ingredient;
Expand All @@ -23,7 +28,6 @@ public class BakingAppWidgetService extends IntentService {
public static final String ACTION_OPEN_RECIPE =
"com.udacity.bakingapp.widget.bakingapp_widget_service";


public BakingAppWidgetService(String name) {
super(name);
}
Expand All @@ -49,6 +53,21 @@ public static void startActionOpenRecipeO(Context context) {
@Override
public void onCreate() {
super.onCreate();

if (Build.VERSION.SDK_INT >= 26) {
String CHANNEL_ID = "my_channel_01";
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
"BakingApp service",
NotificationManager.IMPORTANCE_DEFAULT);

((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).createNotificationChannel(channel);

Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("")
.setContentText("").build();

startForeground(1, notification);
}
}

@Override
Expand Down

0 comments on commit a04933b

Please sign in to comment.