diff --git a/OsmAnd/src/net/osmand/plus/NotificationHelper.java b/OsmAnd/src/net/osmand/plus/NotificationHelper.java index 9451710b39..8e5e46317b 100644 --- a/OsmAnd/src/net/osmand/plus/NotificationHelper.java +++ b/OsmAnd/src/net/osmand/plus/NotificationHelper.java @@ -1,19 +1,23 @@ package net.osmand.plus; -import android.app.Notification; -import android.support.v4.app.NotificationCompat.Builder; -import android.support.v4.app.NotificationManagerCompat; +import java.util.ArrayList; +import java.util.List; import net.osmand.plus.notifications.GpxNotification; import net.osmand.plus.notifications.NavigationNotification; import net.osmand.plus.notifications.OsmandNotification; import net.osmand.plus.notifications.OsmandNotification.NotificationType; - -import java.util.ArrayList; -import java.util.List; +import android.annotation.TargetApi; +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.content.Context; +import android.support.v4.app.NotificationCompat.Builder; +import android.support.v4.app.NotificationManagerCompat; public class NotificationHelper { + public static final String NOTIFICATION_CHANEL_ID = "osmand_background_service"; private OsmandApplication app; private NavigationNotification navigationNotification; @@ -128,4 +132,17 @@ public class NotificationHelper { notification.removeNotification(); } } + + @TargetApi(26) + public void createNotificationChannel() { + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANEL_ID, + app.getString(R.string.osmand_service), NotificationManager.IMPORTANCE_LOW); + channel.enableVibration(false); + channel.setDescription(app.getString(R.string.osmand_service_descr)); + NotificationManager mNotificationManager = (NotificationManager) app + .getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.createNotificationChannel(channel); + } + } } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index ebee76ad00..2d2b63ad11 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -24,6 +24,7 @@ import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.map.WorldRegion; import net.osmand.map.WorldRegion.RegionParams; +import net.osmand.plus.NotificationHelper; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.OsmandPreference; @@ -113,7 +114,10 @@ public class DownloadIndexesThread { Intent contentIntent = new Intent(app, DownloadActivity.class); PendingIntent contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); - Builder bld = new NotificationCompat.Builder(app, NotificationChannel.DEFAULT_CHANNEL_ID); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + app.getNotificationHelper().createNotificationChannel(); + } + Builder bld = new NotificationCompat.Builder(app, NotificationHelper.NOTIFICATION_CHANEL_ID); String msg = Version.getAppName(app); if(!isFinished) { msg = task.getDescription(); diff --git a/OsmAnd/src/net/osmand/plus/notifications/OsmandNotification.java b/OsmAnd/src/net/osmand/plus/notifications/OsmandNotification.java index 3bdfa6295c..99df78bb80 100644 --- a/OsmAnd/src/net/osmand/plus/notifications/OsmandNotification.java +++ b/OsmAnd/src/net/osmand/plus/notifications/OsmandNotification.java @@ -3,13 +3,16 @@ package net.osmand.plus.notifications; import android.annotation.SuppressLint; import android.app.Notification; import android.app.NotificationChannel; +import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.support.v4.app.NotificationCompat.Builder; import android.support.v4.app.NotificationManagerCompat; import android.support.v4.app.NotificationCompat; +import net.osmand.plus.NotificationHelper; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; public abstract class OsmandNotification { @@ -20,6 +23,7 @@ public abstract class OsmandNotification { public final static int WEAR_NAVIGATION_NOTIFICATION_SERVICE_ID = 1005; public final static int WEAR_GPX_NOTIFICATION_SERVICE_ID = 1006; + protected OsmandApplication app; protected boolean ongoing = true; @@ -63,8 +67,10 @@ public abstract class OsmandNotification { Intent contentIntent = new Intent(app, MapActivity.class); PendingIntent contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); - - Builder builder = new Builder(app, NotificationChannel.DEFAULT_CHANNEL_ID) + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + app.getNotificationHelper().createNotificationChannel(); + } + Builder builder = new Builder(app, NotificationHelper.NOTIFICATION_CHANEL_ID) .setVisibility(android.support.v4.app.NotificationCompat.VISIBILITY_PUBLIC) .setPriority(top ? NotificationCompat.PRIORITY_HIGH : getPriority()) .setOngoing(ongoing && !wearable)