mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-12-25 01:20:37 +00:00
android:: fixed the 'game in progress' notifications for Android 28 and 29
This commit is contained in:
parent
4f4a7ccde4
commit
29b17bd8e4
@ -3,14 +3,21 @@ package com.roguetemple.hyperroid;
|
|||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.NotificationChannel;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
|
||||||
public class ForegroundService extends Service {
|
public class ForegroundService extends Service {
|
||||||
|
|
||||||
public static String MAIN_ACTION = "com.roguetemple.hyperroid.action.main";
|
public static String MAIN_ACTION = "com.roguetemple.hyperroid.action.main";
|
||||||
@ -18,6 +25,20 @@ public class ForegroundService extends Service {
|
|||||||
public static String STOPFOREGROUND_ACTION = "com.roguetemple.hyperroid.action.stopforeground";
|
public static String STOPFOREGROUND_ACTION = "com.roguetemple.hyperroid.action.stopforeground";
|
||||||
public static int FOREGROUND_SERVICE = 101;
|
public static int FOREGROUND_SERVICE = 101;
|
||||||
|
|
||||||
|
public String getChannelId() {
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return "";
|
||||||
|
String NOTIFICATION_CHANNEL_ID = "com.roguetemple.hyperrogue";
|
||||||
|
String channelName = "HyperRogue game in progress";
|
||||||
|
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);
|
||||||
|
return NOTIFICATION_CHANNEL_ID;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
if (intent.getAction().equals(STARTFOREGROUND_ACTION)) {
|
if (intent.getAction().equals(STARTFOREGROUND_ACTION)) {
|
||||||
@ -31,7 +52,7 @@ public class ForegroundService extends Service {
|
|||||||
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
|
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
|
||||||
notificationIntent, 0);
|
notificationIntent, 0);
|
||||||
|
|
||||||
Notification notification = new NotificationCompat.Builder(this)
|
Notification notification = new NotificationCompat.Builder(this, getChannelId())
|
||||||
.setContentTitle("HyperRogue")
|
.setContentTitle("HyperRogue")
|
||||||
.setContentText("Game in progress.")
|
.setContentText("Game in progress.")
|
||||||
.setTicker("Game in progress. Game in progress. Game in progress.")
|
.setTicker("Game in progress. Game in progress. Game in progress.")
|
||||||
|
Loading…
Reference in New Issue
Block a user