I'm trying to add 3 buttons to my foreground service notification, but all guides i followed failed
this answer says to add action: https://stackoverflow.com/a/49539463/5679560
this tutorial says to use remoteview https://developer.android.com/training/notify-user/custom-notification
I've tried both options but my notification keeps the default look, even the text doesn't change at all, my notification refers to the foreground service notification is this the problem? isnt possible to add a small button in the foreground service notification?
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this))
startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + this.getPackageName())).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
else if (intent.hasExtra(com.tomatedigital.androidutils.Constants.Intent.WINDOW_SERVICE_LAYOUT)) {
new FloatingWindow(this, LayoutInflater.from(this).inflate(intent.getIntExtra(Constants.Intent.WINDOW_SERVICE_LAYOUT, 0), null), "casa");
startForeground(1, Notification.startFloatingWindow(this));
}
return START_REDELIVER_INTENT;
}
public static android.app.Notification startFloatingWindow(@NonNull final Context context) {
@SuppressLint("RemoteViewLayout") RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification_floating_window);
//HelperActivity will be shown at step 4
/*
Intent stop = new Intent(context, MeuServico.class);
stop.putExtra("stop", "do");//if necessary
PendingIntent pRadio = PendingIntent.getActivity(ctx, 0, radio, 0);
//R.id.radio is a button from the layout which is created at step 2 view.setOnClickPendingIntent(R.id.radio, pRadio);
//Follows exactly my code!
Intent volume = new Intent(ctx, tsapalos11598712.bill3050.shortcuts.helper.HelperActivity.class);
volume.putExtra("DO", "volume");</p >
//HERE is the whole trick. Look at pVolume. I used 1 instead of 0.
PendingIntent pVolume = PendingIntent.getActivity(ctx, 1, volume, 0);
view.setOnClickPendingIntent(R.id.volume, pVolume);
*/
return new NotificationCompat.Builder(context, Constants.Notification.FLOATING_WINDOW_NID)
// .setSmallIcon(R.drawable.ic_notification_logo)
.setContentTitle("getString(R.string.foregroundNotification)")
.setContentText("text")
//.setCustomContentView(contentView)
.addAction(R.drawable.ic_stop, "teste", null)
.setPriority(NotificationCompat.PRIORITY_LOW).build();
}
}
A little more context to the problem. I'm trying to create a floating window and have a service controlling it. Everything runs fine, the service starts -> goes foreground -> creates the floating window which shows fine even when app is background
but i want to add a CLOSE button in the notification so user can close the floating window...
Btw the text in the floating window says "My app is running tap here to see more info" which definitely isn't what i wrote for the notification