fix the notification channel for the main status
This commit is contained in:
@ -1,23 +1,16 @@
|
||||
package net.i2p.android.router.service;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteCallbackList;
|
||||
import android.os.RemoteException;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
import net.i2p.android.router.R;
|
||||
@ -176,41 +169,13 @@ public class RouterService extends Service {
|
||||
_handler.removeCallbacks(_updater);
|
||||
_handler.postDelayed(_updater, 50);
|
||||
if(!restart) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
startOwnForeground();
|
||||
else
|
||||
startForeground(1337, _statusBar.getNote());
|
||||
startForeground(1337, _statusBar.getNote());
|
||||
}
|
||||
|
||||
//return START_STICKY;
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Android 8.1, 9.0, 10 handle foreground applications differently and as such require us to
|
||||
* start our foreground service differently.
|
||||
* */
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
private void startOwnForeground(){
|
||||
String NOTIFICATION_CHANNEL_ID = "com.example.simpleapp";
|
||||
String channelName = "My Background Service";
|
||||
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE);
|
||||
chan.setLightColor(Color.BLUE);
|
||||
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
assert manager != null;
|
||||
manager.createNotificationChannel(chan);
|
||||
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
|
||||
Notification notification = notificationBuilder.setOngoing(true)
|
||||
.setSmallIcon(R.drawable.i2plogo)
|
||||
.setContentTitle(getString(R.string.running_background))
|
||||
.setPriority(NotificationManager.IMPORTANCE_MIN)
|
||||
.setCategory(Notification.CATEGORY_SERVICE)
|
||||
.build();
|
||||
startForeground(1337, notification);
|
||||
}
|
||||
|
||||
/**
|
||||
* maybe this goes away when the receiver can bind to us
|
||||
*/
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.i2p.android.router.service;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
@ -16,6 +17,8 @@ class StatusBar {
|
||||
private final NotificationManager mNotificationManager;
|
||||
private final NotificationCompat.Builder mNotifyBuilder;
|
||||
private Notification mNotif;
|
||||
private final String NOTIFICATION_CHANNEL_ID = "net.i2p.android.STARTUP_STATE_CHANNEL";
|
||||
private final String channelName = "I2P";
|
||||
|
||||
private static final int ID = 1337;
|
||||
|
||||
@ -37,12 +40,22 @@ class StatusBar {
|
||||
// won't be shown if replace() is called
|
||||
String text = ctx.getString(R.string.notification_status_starting);
|
||||
|
||||
mNotifyBuilder = new NotificationCompat.Builder(ctx)
|
||||
.setContentText(text)
|
||||
.setSmallIcon(icon)
|
||||
.setColor(mCtx.getResources().getColor(R.color.primary_light))
|
||||
.setOngoing(true)
|
||||
.setOnlyAlertOnce(true);
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
mNotifyBuilder = new NotificationCompat.Builder(mCtx);
|
||||
} else {
|
||||
mNotifyBuilder = new NotificationCompat.Builder(ctx, NOTIFICATION_CHANNEL_ID);
|
||||
}
|
||||
mNotifyBuilder.setContentText(text);
|
||||
mNotifyBuilder.setSmallIcon(icon);
|
||||
mNotifyBuilder.setColor(mCtx.getResources().getColor(R.color.primary_light));
|
||||
mNotifyBuilder.setOngoing(true);
|
||||
mNotifyBuilder.setOnlyAlertOnce(true);
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
NotificationChannel mNotificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE);
|
||||
mNotificationManager.createNotificationChannel(mNotificationChannel);
|
||||
mNotificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
}
|
||||
|
||||
Intent intent = new Intent(ctx, I2PActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
@ -2,16 +2,23 @@ package net.i2p.android.router.util;
|
||||
|
||||
import net.i2p.android.router.R;
|
||||
|
||||
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.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
public class Notifications {
|
||||
private final Context mCtx;
|
||||
private final NotificationManager mNotificationManager;
|
||||
|
||||
|
||||
|
||||
public static final int ICON = R.drawable.ic_stat_router_active;
|
||||
|
||||
public Notifications(Context ctx) {
|
||||
@ -25,13 +32,26 @@ public class Notifications {
|
||||
}
|
||||
|
||||
public void notify(String title, String text, Class<?> c) {
|
||||
NotificationCompat.Builder b =
|
||||
new NotificationCompat.Builder(mCtx)
|
||||
.setContentTitle(title)
|
||||
.setContentText(text)
|
||||
.setSmallIcon(ICON)
|
||||
.setColor(mCtx.getResources().getColor(R.color.primary_light))
|
||||
.setAutoCancel(true);
|
||||
notify(title, text, "", c);
|
||||
}
|
||||
|
||||
public void notify(String title, String text, String channel, Class<?> c) {
|
||||
NotificationCompat.Builder b;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
b = new NotificationCompat.Builder(mCtx);
|
||||
} else {
|
||||
if (channel.equals("")){
|
||||
b = new NotificationCompat.Builder(mCtx);
|
||||
} else {
|
||||
b = new NotificationCompat.Builder(mCtx, channel);
|
||||
}
|
||||
}
|
||||
|
||||
b.setContentTitle(title);
|
||||
b.setContentText(text);
|
||||
b.setSmallIcon(ICON);
|
||||
b.setColor(mCtx.getResources().getColor(R.color.primary_light));
|
||||
b.setAutoCancel(true);
|
||||
|
||||
if (c != null) {
|
||||
Intent intent = new Intent(mCtx, c);
|
||||
|
Reference in New Issue
Block a user