I'm trying to clear automatically a notification I received from the FirebaseX plugin on Ionic after one minute. It means that even if the user doesn't click on it, I want the notification to disappear.
For that I modified the plugins/cordova-plugin-firebasex/src/android/FirebasePlugin.java file where it appears to have the onMessageReceived function.
I know nothing in Java so I tried to add a sleep method before the same content of the clearAllNotifications function as this :
private void onMessageReceived(final CallbackContext callbackContext) {
FirebasePlugin.notificationCallbackContext = callbackContext;
if (FirebasePlugin.notificationStack != null) {
for (Bundle bundle : FirebasePlugin.notificationStack) {
FirebasePlugin.sendMessage(bundle, applicationContext);
}
FirebasePlugin.notificationStack.clear();
}
// I want to wait one minute before it executes the code
TimeUnit.SECONDS.sleep(60);
// This code is a copy/paste from the clearAllNotifications function
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
NotificationManager nm = (NotificationManager) applicationContext.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancelAll();
callbackContext.success();
} catch (Exception e) {
handleExceptionWithContext(e, callbackContext);
}
}
});
}
But I receive an error when I try to build the app :
platforms/android/app/src/main/java/org/apache/cordova/firebase/FirebasePlugin.java:485: error: unreported exception InterruptedException; must be caught or declared to be thrown TimeUnit.SECONDS.sleep(3);
How could I do to automatically clear a notification after some time ? I've already tried with the Handler method as suggested here but I have a similar error, maybe i'm not importing it well.
Thanks