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.
This commit is contained in:
Eric House 2018-12-14 17:12:15 -08:00
parent 02897f6e36
commit f7ef1adcb5
2 changed files with 27 additions and 8 deletions

View file

@ -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();
}

View file

@ -2031,6 +2031,7 @@
<string name="bkng_notify_text">Accepting Bluetooth messages…</string>
<string name="bkng_stop_text">Stop</string>
<string name="bkng_settings_text">Settings</string>
<!-- -->
<string name="confirm_sms_title">Confirm your SMS plan</string>
@ -2728,7 +2729,7 @@
<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>
<string name="foreground_channel_expl">Accepting Bluetooth in background</string>
<!-- Explanation in settings for traditional move-arrived notification -->
<string name="gameevent_channel_expl">In-game events</string>
</resources>