Open camden-kid opened 7 years ago
Same here!! When the user opens the app directly without tapping the notifications on the notification tray, then how to clear the system tray notifications?? Plz help me if you get any solutions on this @camden-kid
You have to rewrite the MainActivity in order to clean them.
this is my MainActivity (you can find it in platforms>android>nameofpackage
import android.os.Bundle;
import org.apache.cordova.*;
import android.app.NotificationManager;
import android.content.Context;
public class MainActivity extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
moveTaskToBack(true);
}
final NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
loadUrl(launchUrl);
}
@Override
protected void onResume() {
super.onResume();
final NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
}
}
Thanks for the update. But what about iOS? I request the author, plz implement this feature in the plugin itself.
Hello, I'm having the same problem here, the thing is that the installed plugin already includes this update but this is not working for me. And the push notifications in the system tray aren't cleared after i access the application. Any workaround , or a solution for this problem ?
Is there any way to achieve this on iOS ?
I cannot get @ibonkonesa solution to work. I get a build failure due to symbol "launchUrl" not being found. Does anyone knows how to fix this? Thanks
A slight modification in @ibonkonesa solution.
For version 2.1.2 (Android only)
Notification can be cleared by adding below snippet in
plugins > cordova-plugin-fcm > android > FCMPluginActivity.java
Code snippet:
final NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
Add this in oncreate method before forceMainActivityReload().
Thanks to @ibonkonesa for reference.
Is there a way with this plugin to clear the notification tray from within the app. My requirement is to clear any notifications if the user access a certain part of the app.
The only way I can see to clear the notification is to tap on it or tap the clear button (on Android).