mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-08 05:24:39 +01:00
use separate channel for background service notification
Since on newer OS versions users might want to hide it
This commit is contained in:
parent
2ab04901a7
commit
02897f6e36
3 changed files with 11 additions and 30 deletions
|
@ -577,14 +577,15 @@ public class BTService extends XWService {
|
|||
PendingIntent stopPI =
|
||||
PendingIntent.getBroadcast(this, 0, stopIntent, 0);
|
||||
|
||||
m_notification =
|
||||
new NotificationCompat.Builder( this, Utils.getChannelId(this) )
|
||||
String channelID = Channels.getChannelID( this, Channels.ID.FOREGROUND );
|
||||
NotificationCompat.Builder builder =
|
||||
new NotificationCompat.Builder( this, channelID )
|
||||
.setSmallIcon( R.drawable.notify_btservice )
|
||||
.setContentText( getString(R.string.bkng_notify_text) )
|
||||
.setContentIntent( pendIntent )
|
||||
.addAction( R.drawable.notify_btservice,
|
||||
getString(R.string.bkng_stop_text), stopPI )
|
||||
.build();
|
||||
getString(R.string.bkng_stop_text), stopPI );
|
||||
m_notification = builder.build();
|
||||
}
|
||||
|
||||
Log.d( TAG, "calling service.startForeground()" );
|
||||
|
|
|
@ -83,8 +83,6 @@ public class Utils {
|
|||
private static final String TAG = Utils.class.getSimpleName();
|
||||
public static final int TURN_COLOR = 0x7F00FF00;
|
||||
|
||||
private static final String _CHANNEL_ID = BuildConfig.APPLICATION_ID + "_channel_id";
|
||||
|
||||
private static final String DB_PATH = "XW_GAMES";
|
||||
private static final String HIDDEN_PREFS = "xwprefs_hidden";
|
||||
private static final String FIRST_VERSION_KEY = "FIRST_VERSION_KEY";
|
||||
|
@ -258,8 +256,9 @@ public class Utils {
|
|||
defaults |= Notification.DEFAULT_VIBRATE;
|
||||
}
|
||||
|
||||
String channelID = Channels.getChannelID( context, Channels.ID.GAME_EVENT );
|
||||
Notification notification =
|
||||
new NotificationCompat.Builder( context, getChannelId(context) )
|
||||
new NotificationCompat.Builder( context, channelID )
|
||||
.setContentIntent( pi )
|
||||
.setSmallIcon( R.drawable.notify )
|
||||
//.setTicker(body)
|
||||
|
@ -620,27 +619,4 @@ public class Utils {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean sChannelMade = false;
|
||||
static String getChannelId( Context context )
|
||||
{
|
||||
if ( !sChannelMade ) {
|
||||
sChannelMade = true;
|
||||
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) {
|
||||
NotificationManager notMgr = (NotificationManager)
|
||||
context.getSystemService( Context.NOTIFICATION_SERVICE );
|
||||
|
||||
String channelDescription = "XWORDS Default Channel";
|
||||
NotificationChannel channel = notMgr.getNotificationChannel( _CHANNEL_ID );
|
||||
if ( channel == null ) {
|
||||
channel = new NotificationChannel( _CHANNEL_ID, channelDescription,
|
||||
NotificationManager.IMPORTANCE_LOW );
|
||||
// channel.setLightColor(Color.GREEN);
|
||||
channel.enableVibration( true );
|
||||
notMgr.createNotificationChannel( channel );
|
||||
}
|
||||
}
|
||||
}
|
||||
return _CHANNEL_ID;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2727,4 +2727,8 @@
|
|||
<string name="perms_rationale_title">Android Permissions</string>
|
||||
<string name="toast_no_permission">Permission not granted</string>
|
||||
|
||||
<!-- Explanation in settings for always-on BT notification -->
|
||||
<string name="foreground_channel_expl">Ready-for-bluetooth</string>
|
||||
<!-- Explanation in settings for traditional move-arrived notification -->
|
||||
<string name="gameevent_channel_expl">In-game events</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue