diff --git a/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java b/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java index 2c79ea8..11bd0f4 100644 --- a/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java +++ b/app/src/main/java/net/foucry/pilldroid/PillDroidJobService.java @@ -2,7 +2,6 @@ package net.foucry.pilldroid; import android.app.NotificationChannel; import android.app.NotificationManager; -import android.app.PendingIntent; import android.app.job.JobParameters; import android.app.job.JobService; import android.content.Intent; @@ -10,7 +9,6 @@ import android.icu.util.Calendar; import android.util.Log; import androidx.core.app.NotificationCompat; -import androidx.core.app.NotificationManagerCompat; import java.util.List; @@ -29,10 +27,9 @@ public class PillDroidJobService extends JobService { @Override public boolean onStartJob(JobParameters params) { Log.d(TAG, "Job started"); - createNotificationChannel(); doBackgroundWork(params); - return true; + return false; } /** @@ -75,7 +72,7 @@ public class PillDroidJobService extends JobService { public boolean onStopJob(JobParameters params) { Log.d(TAG, "Job cancelled before completion"); jobCancelled = true; - return true; + return false; } /** @@ -83,7 +80,7 @@ public class PillDroidJobService extends JobService { */ private void scheduleNotification() { Log.d(TAG, "schedule notification"); - createNotificationChannel(); + /*createNotificationChannel(); Intent intent = new Intent(this, MedicamentListActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) @@ -96,7 +93,19 @@ public class PillDroidJobService extends JobService { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); int notificationId = 666; - notificationManager.notify(notificationId, builder.build()); + notificationManager.notify(notificationId, builder.build());*/ + + NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O){ + NotificationChannel notificationChannel = new NotificationChannel("123", "Pilldroid", NotificationManager.IMPORTANCE_DEFAULT); + notificationManager.createNotificationChannel(notificationChannel); + } + + NotificationCompat.Builder notification = new NotificationCompat.Builder(getApplicationContext(), "123") + .setContentTitle(getString(R.string.app_name)) + .setContentText(getString(R.string.notification_text)) + .setSmallIcon(R.drawable.ic_pill_alarm); + notificationManager.notify(1, notification.build()); } @@ -109,6 +118,7 @@ public class PillDroidJobService extends JobService { CharSequence name = getString(R.string.channel_name); String description = getString(R.string.channel_description); int importance = NotificationManager.IMPORTANCE_DEFAULT; + String CHANNEL_ID = "PillDroid"; NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance); channel.setDescription(description); // Register the channel with the system; you can't change the importance