cordova-plugin-local-notifications
cordova-plugin-local-notifications copied to clipboard
open application that is running in background white clic on the option of notification
WARNING: IF YOU IGNORE THIS TEMPLATE, WE'LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!
Provide a general summary of the issue.
Your Environment
-
Plugin version: 0.9.0-beta.2
-
Platform: android
-
OS version: 7.1.1
-
Device manufacturer / model: huawei
-
Cordova version (
cordova -v
): 9.0.0 ([email protected]) -
Cordova platform version (
cordova platform ls
): android 8.1.0 -
Plugin config
-
Ionic Version (if using Ionic) 6.5.0
Expected Behavior
when i'm using the action in the option of notification ,in the case my application in background, clic on the option of notification dont open my application, but the clic on the notification open the application, for now i'm using 'cordova-plugin-app-launcher' to resolve this probleme, but i want to use only the notification plugin in my app, some help
Actual Behavior
when i'm using the action in the option of notification ,in the case my application in background, clic on the option of notification dont open my application, but the clic on the notification open the application, for now i'm using 'cordova-plugin-app-launcher' to resolve this probleme, but i want to use only the notification plugin in my app, some help
Steps to Reproduce
that is my code : this.localNotifications.schedule({ title: 'Do you want to see this discussion?', actions: [{ id: this.idDiscussion, title: 'Open' }] });
this.subscribre = this.localNotifications.on(this.idDiscussion).subscribe((action:any) => { console.log('id discussion ', this.idDiscussion) this.launcher.canLaunch({packageName:'io.ionic.notif'}).then(ok => { console.log(ok) this.launcher.launch({packageName:'io.ionic.notif'}).then(open => { console.log(open); }) }) .catch(ko => { console.log(ko) })
this.subscribre.unsubscribe();
})
Context
i want to open my application that is running in background
Debug logs
i dont have any error message
You can use cordova-plugin-background-mode plugin to enable running in background for your application and then on notification click you can use moveToForeground() method, look at the example (it works for me)
function onDeviceReady() {
cordova.plugins.backgroundMode.enable();
cordova.plugins.backgroundMode.setDefaults({ silent: true });
cordova.plugins.backgroundMode.disableBatteryOptimizations();
cordova.plugins.notification.local.schedule({
title: 'Do you want to go see a movie tonight?',
actions: [{ id: 'yes', title: 'Yes' }]
});
cordova.plugins.notification.local.on('yes', function (notification, eopts) {
console.log("NOTIFICATION EVENT FIRED", notification, eopts);
cordova.plugins.backgroundMode.moveToForeground(); //app comes to foreground
});
}
I hope this will help you
I have same things. But i have an error on logcat (AndroidStudio - device : Samsung A50 on Android 11) :
I/chromium: [INFO:CONSOLE(2153)] "click on actions NOTIF YES => [object Object]", source: http://localhost/main.js (2153)
W/cr_AwContents: WebView.destroy() called while WebView is still attached to window.
I/ViewRootImpl@4bd85e4[MainActivity]: dispatchDetachedFromWindow
W/cr_AwContents: Application attempted to call on a destroyed WebView
java.lang.Throwable
at org.chromium.android_webview.AwContents.r(chromium-TrichromeWebViewGoogle.aab-stable-447208833:2)
at Sa.loadingStateChanged(chromium-TrichromeWebViewGoogle.aab-stable-447208833:2)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:335)
at android.os.Looper.loop(Looper.java:206)
at android.app.ActivityThread.main(ActivityThread.java:8506)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
My code :
this.localNotifications.schedule({
id: 1,
title: "Test Title",
text: "Test Text",
trigger: { at: new Date(new Date().getTime() + 10000) },
launch: true,
lockscreen: true,
wakeup: true,
vibrate: true,
actions: [
{ id: "action-yes", title: "Yes" },
{ id: "action-no", title: "No" }
]
});
this.localNotifications.on("action-yes").subscribe(data => {
console.log("click NOTIF YES => ", data);
});
Some idea ?
Ok i found the problem : need to put a launch parameter to true ! :)
actions: [
{ id: "action-yes", title: "Yes", launch: true },
{ id: "action-no", title: "No", launch: true }
]