Skip to content

Commit

Permalink
more cleanly isolate notification channel code
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Feb 6, 2019
1 parent dcce577 commit 4b808e6
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/main/java/org/havenapp/main/service/MonitorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@


import android.annotation.SuppressLint;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
Expand All @@ -26,6 +24,7 @@
import android.telephony.SmsManager;
import android.text.TextUtils;

import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;

import org.havenapp.main.HavenApp;
Expand Down Expand Up @@ -57,8 +56,6 @@ public class MonitorService extends Service {
/**
* To show a notification on service start
*/
private NotificationManager manager;
private NotificationChannel mChannel;
private final static String channelId = "monitor_id";
private final static CharSequence channelName = "Haven notifications";
private final static String channelDescription= "Important messages from Haven";
Expand Down Expand Up @@ -129,16 +126,10 @@ public void onCreate() {

mApp = (HavenApp)getApplication();

manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
mPrefs = new PreferenceManager(this);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mChannel = new NotificationChannel(channelId, channelName,
NotificationManager.IMPORTANCE_HIGH);
mChannel.setDescription(channelDescription);
mChannel.setLightColor(Color.RED);
mChannel.setImportance(NotificationManager.IMPORTANCE_MIN);
manager.createNotificationChannel(mChannel);
setupNotificationChannel();
}

startSensors();
Expand All @@ -153,6 +144,19 @@ public void onCreate() {
wakeLock.acquire();
}

@RequiresApi(api = Build.VERSION_CODES.O)
private void setupNotificationChannel ()
{
android.app.NotificationManager manager = (android.app.NotificationManager)getSystemService(NOTIFICATION_SERVICE);
android.app.NotificationChannel channel;
channel = new android.app.NotificationChannel(channelId, channelName,
android.app.NotificationManager.IMPORTANCE_HIGH);
channel.setDescription(channelDescription);
channel.setLightColor(Color.RED);
channel.setImportance(android.app.NotificationManager.IMPORTANCE_MIN);
manager.createNotificationChannel(channel);
}

public static MonitorService getInstance ()
{
return sInstance;
Expand Down

0 comments on commit 4b808e6

Please sign in to comment.