Merge "Use notification action to stop recording" into sc-dev

This commit is contained in:
Beth Thibodeau
2021-06-24 17:02:18 +00:00
committed by Android (Google) Code Review

View File

@@ -291,19 +291,24 @@ public class RecordingService extends Service implements MediaRecorder.OnInfoLis
? res.getString(R.string.screenrecord_ongoing_screen_only) ? res.getString(R.string.screenrecord_ongoing_screen_only)
: res.getString(R.string.screenrecord_ongoing_screen_and_audio); : res.getString(R.string.screenrecord_ongoing_screen_and_audio);
Intent stopIntent = getNotificationIntent(this); PendingIntent pendingIntent = PendingIntent.getService(
this,
REQUEST_CODE,
getNotificationIntent(this),
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
Notification.Action stopAction = new Notification.Action.Builder(
Icon.createWithResource(this, R.drawable.ic_android),
getResources().getString(R.string.screenrecord_stop_label),
pendingIntent).build();
Notification.Builder builder = new Notification.Builder(this, CHANNEL_ID) Notification.Builder builder = new Notification.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_screenrecord) .setSmallIcon(R.drawable.ic_screenrecord)
.setContentTitle(notificationTitle) .setContentTitle(notificationTitle)
.setContentText(getResources().getString(R.string.screenrecord_stop_text))
.setUsesChronometer(true) .setUsesChronometer(true)
.setColorized(true) .setColorized(true)
.setColor(getResources().getColor(R.color.GM2_red_700)) .setColor(getResources().getColor(R.color.GM2_red_700))
.setOngoing(true) .setOngoing(true)
.setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_IMMEDIATE) .setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_IMMEDIATE)
.setContentIntent( .addAction(stopAction)
PendingIntent.getService(this, REQUEST_CODE, stopIntent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE))
.addExtras(extras); .addExtras(extras);
startForeground(NOTIFICATION_RECORDING_ID, builder.build()); startForeground(NOTIFICATION_RECORDING_ID, builder.build());
} }