Update default notification
This commit is contained in:
parent
46a5cedf8d
commit
3320291426
3 changed files with 36 additions and 9 deletions
|
@ -1,19 +1,23 @@
|
||||||
package net.osmand.plus;
|
package net.osmand.plus;
|
||||||
|
|
||||||
import android.app.Notification;
|
import java.util.ArrayList;
|
||||||
import android.support.v4.app.NotificationCompat.Builder;
|
import java.util.List;
|
||||||
import android.support.v4.app.NotificationManagerCompat;
|
|
||||||
|
|
||||||
import net.osmand.plus.notifications.GpxNotification;
|
import net.osmand.plus.notifications.GpxNotification;
|
||||||
import net.osmand.plus.notifications.NavigationNotification;
|
import net.osmand.plus.notifications.NavigationNotification;
|
||||||
import net.osmand.plus.notifications.OsmandNotification;
|
import net.osmand.plus.notifications.OsmandNotification;
|
||||||
import net.osmand.plus.notifications.OsmandNotification.NotificationType;
|
import net.osmand.plus.notifications.OsmandNotification.NotificationType;
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import java.util.ArrayList;
|
import android.app.Notification;
|
||||||
import java.util.List;
|
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 class NotificationHelper {
|
||||||
|
|
||||||
|
public static final String NOTIFICATION_CHANEL_ID = "osmand_background_service";
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
|
||||||
private NavigationNotification navigationNotification;
|
private NavigationNotification navigationNotification;
|
||||||
|
@ -128,4 +132,17 @@ public class NotificationHelper {
|
||||||
notification.removeNotification();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import net.osmand.IndexConstants;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.map.WorldRegion;
|
import net.osmand.map.WorldRegion;
|
||||||
import net.osmand.map.WorldRegion.RegionParams;
|
import net.osmand.map.WorldRegion.RegionParams;
|
||||||
|
import net.osmand.plus.NotificationHelper;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
||||||
|
@ -113,7 +114,10 @@ public class DownloadIndexesThread {
|
||||||
Intent contentIntent = new Intent(app, DownloadActivity.class);
|
Intent contentIntent = new Intent(app, DownloadActivity.class);
|
||||||
PendingIntent contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent,
|
PendingIntent contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent,
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
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);
|
String msg = Version.getAppName(app);
|
||||||
if(!isFinished) {
|
if(!isFinished) {
|
||||||
msg = task.getDescription();
|
msg = task.getDescription();
|
||||||
|
|
|
@ -3,13 +3,16 @@ package net.osmand.plus.notifications;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.v4.app.NotificationCompat.Builder;
|
import android.support.v4.app.NotificationCompat.Builder;
|
||||||
import android.support.v4.app.NotificationManagerCompat;
|
import android.support.v4.app.NotificationManagerCompat;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
import net.osmand.plus.NotificationHelper;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
|
||||||
public abstract class OsmandNotification {
|
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_NAVIGATION_NOTIFICATION_SERVICE_ID = 1005;
|
||||||
public final static int WEAR_GPX_NOTIFICATION_SERVICE_ID = 1006;
|
public final static int WEAR_GPX_NOTIFICATION_SERVICE_ID = 1006;
|
||||||
|
|
||||||
|
|
||||||
protected OsmandApplication app;
|
protected OsmandApplication app;
|
||||||
protected boolean ongoing = true;
|
protected boolean ongoing = true;
|
||||||
|
@ -63,8 +67,10 @@ public abstract class OsmandNotification {
|
||||||
Intent contentIntent = new Intent(app, MapActivity.class);
|
Intent contentIntent = new Intent(app, MapActivity.class);
|
||||||
PendingIntent contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent,
|
PendingIntent contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent,
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||||
Builder builder = new Builder(app, NotificationChannel.DEFAULT_CHANNEL_ID)
|
app.getNotificationHelper().createNotificationChannel();
|
||||||
|
}
|
||||||
|
Builder builder = new Builder(app, NotificationHelper.NOTIFICATION_CHANEL_ID)
|
||||||
.setVisibility(android.support.v4.app.NotificationCompat.VISIBILITY_PUBLIC)
|
.setVisibility(android.support.v4.app.NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
.setPriority(top ? NotificationCompat.PRIORITY_HIGH : getPriority())
|
.setPriority(top ? NotificationCompat.PRIORITY_HIGH : getPriority())
|
||||||
.setOngoing(ongoing && !wearable)
|
.setOngoing(ongoing && !wearable)
|
||||||
|
|
Loading…
Reference in a new issue