Totally rewrite

This commit is contained in:
jacques 2020-12-07 11:29:07 +01:00
parent 42710f5f25
commit 222415f0f9

View file

@ -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