Cleanning import;

Fix CHANNEL_ID bug (at least)
This commit is contained in:
jacques 2020-09-11 11:33:08 +02:00
parent ad889b8a94
commit f27abe2d8b

View file

@ -1,18 +1,10 @@
package net.foucry.pilldroid; package net.foucry.pilldroid;
import android.app.AlarmManager;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.job.JobParameters; import android.app.job.JobParameters;
import android.app.job.JobService; import android.app.job.JobService;
import android.content.Context;
import android.content.Intent;
import android.icu.util.Calendar; import android.icu.util.Calendar;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.SystemClock;
import android.util.Log; import android.util.Log;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
@ -21,8 +13,6 @@ import androidx.core.app.NotificationManagerCompat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import static net.foucry.pilldroid.NotificationPublisher.NOTIFICATION_ID;
/** /**
* Created by jacques on 17/09/16. * Created by jacques on 17/09/16.
@ -31,13 +21,14 @@ import static net.foucry.pilldroid.NotificationPublisher.NOTIFICATION_ID;
public class PillDroidJobService extends JobService { public class PillDroidJobService extends JobService {
private static final String TAG = JobService.class.getName(); private static final String TAG = JobService.class.getName();
private boolean jobCancelled = false; private boolean jobCancelled = false;
private String CHANNEL_ID = "pillDroid";
private String CHANNEL_ID = null;
private DBHelper dbHelper = new DBHelper(this); private DBHelper dbHelper = new DBHelper(this);
@Override @Override
public boolean onStartJob(JobParameters params) { public boolean onStartJob(JobParameters params) {
Log.d(TAG, "Job started"); Log.d(TAG, "Job started");
createNotificationChannel();
doBackgroundWork(params); doBackgroundWork(params);
return true; return true;
@ -79,8 +70,7 @@ public class PillDroidJobService extends JobService {
} }
long delay = dateSchedule - now.getTime(); long delay = dateSchedule - now.getTime();
createNotificationChannel(); scheduleNotification(delay);
scheduleNotification(getApplicationContext(), delay);
} }
Log.d(TAG, "Job finished"); Log.d(TAG, "Job finished");
@ -98,12 +88,11 @@ public class PillDroidJobService extends JobService {
/** /**
* Schedule Notification for the delay * Schedule Notification for the delay
* @param Context context * @param Context context
* @param long delay - date for the notification in milliseconds * @param long delay - date for the notification in millisecond
* @param context
*/ */
private void scheduleNotification(Context context, long delay) { private void scheduleNotification(long delay) {
Log.d(TAG, "scheduleNotification delay == " + delay); Log.d(TAG, "scheduleNotification delay == " + delay);
createNotificationChannel();
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_pill) .setSmallIcon(R.drawable.ic_pill)
.setContentTitle(getString(R.string.app_name)) .setContentTitle(getString(R.string.app_name))
@ -119,8 +108,6 @@ public class PillDroidJobService extends JobService {
/** /**
* createNotificationChannelid for android API >= 28 * createNotificationChannelid for android API >= 28
* @param Context context
* @return String channel_id
*/ */
private void createNotificationChannel() { private void createNotificationChannel() {
@ -133,7 +120,15 @@ public class PillDroidJobService extends JobService {
// Register the channel with the system; you can't change the importance // Register the channel with the system; you can't change the importance
// or other notification behaviors after this // or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class); NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel); try {
notificationManager.createNotificationChannel(channel);
} catch (Exception e) {
// This will catch any exception, because they are all descended from Exception
Log.e(TAG, e.toString());
//At the level Exception Class handle the error in Exception Table
// Exception Create That Error Object and throw it
//E.g: FileNotFoundException ,etc
e.printStackTrace();
}
} }
} }