summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristos Papageorgiou <root.expert.xda@gmail.com>2019-07-08 15:12:23 +0300
committerJulian Veit <claymore1298@gmail.com>2019-07-19 14:53:34 +0200
commit901e652275ef109fe4e8d35c1a2e8076e47381a8 (patch)
treeec2bb5fd3882e038cd16c4648574beac735975e3
parented82b3c645e6db067750bc8c5cc5362606e3fe16 (diff)
JamesDSP: Add notification channel.
-rw-r--r--app/src/main/java/james/dsp/receiver/BootCompletedReceiver.java34
1 files changed, 32 insertions, 2 deletions
diff --git a/app/src/main/java/james/dsp/receiver/BootCompletedReceiver.java b/app/src/main/java/james/dsp/receiver/BootCompletedReceiver.java
index 08a0b6d..a110290 100644
--- a/app/src/main/java/james/dsp/receiver/BootCompletedReceiver.java
+++ b/app/src/main/java/james/dsp/receiver/BootCompletedReceiver.java
@@ -1,22 +1,52 @@
package james.dsp.receiver;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.os.Build;
+import android.support.annotation.RequiresApi;
+
+import james.dsp.R;
+
import james.dsp.service.HeadsetService;
+import static james.dsp.activity.DSPManager.NOTIFICATION_CHANNEL;
+
/**
* This receiver starts our {@link HeadsetService} after system boot. Since
* Android 2.3, we will always need a persistent process, because we are forced
* to keep track of all open audio sessions.
*
- * @Co-founder alankila
+ * Co-founder alankila
*/
public class BootCompletedReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
- context.startForegroundService(new Intent(context, HeadsetService.class));
+ Intent service = new Intent(context, HeadsetService.class);
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ initializeNotificationChannel(context);
+ context.startForegroundService(service);
+ } else {
+ context.startService(service);
+ }
+ }
+
+ @RequiresApi(api = Build.VERSION_CODES.O)
+ private void initializeNotificationChannel(Context context) {
+ final CharSequence name = context.getString(R.string.notification_channel_name);
+ final int importance = NotificationManager.IMPORTANCE_LOW;
+
+ NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL, name, importance);
+
+ // Register the channel with the system; you can't change the importance
+ // or other notification behaviors after this
+ NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
+ if (notificationManager != null)
+ notificationManager.createNotificationChannel(channel);
}
+
}