From f7ef1adcb514b10adadc813058b7ca1f15f8c31c Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 14 Dec 2018 17:12:15 -0800 Subject: [PATCH] add settings button to foreground service notification On O and beyond it's possible to tweak notification channels separately, meaning users can hide the new BT-is-running notification and still get game event notifications. So add a button that takes you to the right Settings app page. --- .../org/eehouse/android/xw4/BTService.java | 32 +++++++++++++++---- .../app/src/main/res/values/strings.xml | 3 +- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java index f4a35c904..a2d74f2ad 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java @@ -34,6 +34,7 @@ import android.content.Intent; import android.os.Build; import android.os.Handler; import android.os.SystemClock; +import android.provider.Settings; import android.support.v4.app.NotificationCompat; import org.eehouse.android.xw4.MultiService.DictFetchOwner; @@ -238,7 +239,7 @@ public class BTService extends XWService { public static void openBTSettings( Activity activity ) { Intent intent = new Intent(); - intent.setAction( android.provider.Settings.ACTION_BLUETOOTH_SETTINGS ); + intent.setAction( Settings.ACTION_BLUETOOTH_SETTINGS ); activity.startActivity( intent ); } @@ -572,19 +573,36 @@ public class BTService extends XWService { .getActivity( this, Utils.nextRandomInt(), notifIntent, PendingIntent.FLAG_ONE_SHOT ); - Intent stopIntent = new Intent(this, BTReceiver.class); - stopIntent.setAction( BTReceiver.ACTION_STOP_BT ); - PendingIntent stopPI = - PendingIntent.getBroadcast(this, 0, stopIntent, 0); - 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, + ; + + // Add button to kill the foreground service + Intent stopIntent = new Intent( this, BTReceiver.class ); + stopIntent.setAction( BTReceiver.ACTION_STOP_BT ); + PendingIntent stopPI = + PendingIntent.getBroadcast(this, 0, stopIntent, 0); + builder.addAction( R.drawable.notify_btservice, getString(R.string.bkng_stop_text), stopPI ); + + // If supported, button to take user to settings (to make + // notification less annoying perhaps) + if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) { + Intent hideIntent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) + .putExtra( Settings.EXTRA_APP_PACKAGE, getPackageName() ) + .putExtra( Settings.EXTRA_CHANNEL_ID, channelID ) + ; + PendingIntent hidePI = + PendingIntent.getActivity( this, 0, hideIntent, 0 ); + builder.addAction( R.drawable.notify_btservice, + getString(R.string.bkng_settings_text), + hidePI ); + } + m_notification = builder.build(); } diff --git a/xwords4/android/app/src/main/res/values/strings.xml b/xwords4/android/app/src/main/res/values/strings.xml index bd57ba9d4..ddf5d2c8b 100644 --- a/xwords4/android/app/src/main/res/values/strings.xml +++ b/xwords4/android/app/src/main/res/values/strings.xml @@ -2031,6 +2031,7 @@ Accepting Bluetooth messages… Stop + Settings Confirm your SMS plan @@ -2728,7 +2729,7 @@ Permission not granted - Ready-for-bluetooth + Accepting Bluetooth in background In-game events