Closed worm69 closed 2 years ago
Android shows notifications in foreground by default. You have to do extra dev work to disable that at the moment.
@rlepinski thx for quick reply. For now i will drop that feature for now but any tips how i can do that on Android?
@worm69 What is your goal? Making sure they display in the foreground or not?
my goal is be able to show them on foreground if i need
Here is a custom notification provider that you can use to suppress notifications in the foreground (default is to show them), but you can add additional flags if you want:
class CustomNotificationProvider extends AirshipNotificationProvider {
public CustomNotificationProvider(@NonNull Context context, @NonNull AirshipConfigOptions configOptions) {
super(context, configOptions);
}
@NonNull
@Override
public NotificationResult onCreateNotification(@NonNull Context context, @NonNull NotificationArguments arguments) {
if (!shouldDisplay(context, arguments)) {
return NotificationResult.cancel();
}
return super.onCreateNotification(context, arguments);
}
private boolean shouldDisplay(@NonNull Context context, @NonNull NotificationArguments arguments) {
if (GlobalActivityMonitor.shared(context).isAppForegrounded()) {
// Do whatever you want here
return false;
} else {
return true;
}
}
}
Set the provider in the Autopilot#onAirshipReady callback:
CustomNotificationProvider provider = new CustomNotificationProvider(UAirship.getApplicationContext(), airship.getAirshipConfigOptions());
airship.getPushManager().setNotificationProvider(provider);
Hopefully in a future release you can just say UAirship.shared().getPushManager().isForegroundNotificationDisplayEnabled(false);
or something of those sorts
Many thanks @rlepinski have a good weekend
Hi, how i can show push notifications while app is on foreground? iOS have PushNotificationDelegate and on Android how i can do that?