Giter Club home page Giter Club logo

Comments (50)

powowbox avatar powowbox commented on June 21, 2024 4

Hi,
I've done a fix to make notifications clickable on android 12+. You can find it here https://github.com/powowbox/cordova-plugin-local-notification-12. If it's ok I will make a PR.
Important: add <preference name="AndroidLaunchMode" value="singleInstance"/> in your config.xml, to avoid to launch the app even if it's in background.

from cordova-plugin-local-notifications.

bhandaribhumin avatar bhandaribhumin commented on June 21, 2024 1

@rafaellop please use my fork version https://github.com/bhandaribhumin/cordova-plugin-local-notification-12, this version includes all latest fixes and also compatible with sdk 30,31,32 and 33 as well.
Please let me know if you found any issues.

Also use this method to request permission https://github.com/bhandaribhumin/cordova-plugin-local-notification-12#setdummynotification

This plugin also available on npm https://www.npmjs.com/package/cordova-plugin-local-notification-12

from cordova-plugin-local-notifications.

powowbox avatar powowbox commented on June 21, 2024 1

@Filavision Hi.
On my fork, If an action is set, the click on the notification is disabled to avoid the user clicks involuntary on the notification before discovering the action button.
I see 2 options: you add another button ‘open app’ or I restore the previous behavior and add an option ‘disableNotificationClick’.

from cordova-plugin-local-notifications.

powowbox avatar powowbox commented on June 21, 2024 1

@fquirin
Hi, my fork is fully functional on android 12 and 13. Just be careful, if you use action buttons in your notifications. In this case, I voluntarily disable the click on the notification to avoid the user clicks on notification before discovering the buttons.

from cordova-plugin-local-notifications.

powowbox avatar powowbox commented on June 21, 2024 1

@fquirin
For the change list, look at the section "Purpose of this fork" on the page of the fork.
I've done several tests since the last two weeks on android 7, 12 and 13 and I didn't notice any problem.

from cordova-plugin-local-notifications.

thiagoroc avatar thiagoroc commented on June 21, 2024 1

Hi, I've done a fix to make notifications clickable on android 12+. You can find it here https://github.com/powowbox/cordova-plugin-local-notification-12. If it's ok I will make a PR. Important: add <preference name="AndroidLaunchMode" value="singleInstance"/> in your config.xml, to avoid to launch the app even if it's in background.

This is solution for my problem. Thanks!

from cordova-plugin-local-notifications.

fragfeaster777 avatar fragfeaster777 commented on June 21, 2024

Related:

wix/react-native-notifications#884
#1989
#1970

from cordova-plugin-local-notifications.

Filavision avatar Filavision commented on June 21, 2024

I have the same issue...

from cordova-plugin-local-notifications.

rafaellop avatar rafaellop commented on June 21, 2024

The issue and solution is described here:
https://proandroiddev.com/notification-trampoline-restrictions-android12-7d2a8b15bbe2

from cordova-plugin-local-notifications.

rafaellop avatar rafaellop commented on June 21, 2024

@bhandaribhumin or @DavidTalevski could you look please at it?

from cordova-plugin-local-notifications.

DavidTalevski avatar DavidTalevski commented on June 21, 2024

Can you try my fork and confirm if the issue persists there?

from cordova-plugin-local-notifications.

Filavision avatar Filavision commented on June 21, 2024

Can you try my fork and confirm if the issue persists there?

The app still doesn't open when i click on the notification. I have also a refresh button at the notification which refresh a random number in the notification. This button also doesn't work anymore with your fork.

from cordova-plugin-local-notifications.

DavidTalevski avatar DavidTalevski commented on June 21, 2024

Can you try my fork and confirm if the issue persists there?

The app still doesn't open when i click on the notification. I have also a refresh button at the notification which refresh a random number in the notification. This button also doesn't work anymore with your fork.

Are there any errors reported in logcat?

from cordova-plugin-local-notifications.

Filavision avatar Filavision commented on June 21, 2024

Tested again. The refresh button works (don't know what happens at the first test) but the app doesn't come in foreground / open when clicking on the notification.

Logcat:

10-22 15:48:01.240  1285  4684 D ActivityTaskManager: startActivityAsUser: callingPid=1428, callingUid=10399, caller=com.android.server.wm.ActivityTaskManagerService.startActivityAsUser:1739 com.android.server.wm.ActivityTaskManagerService.startActivity:1692 android.app.IActivityTaskManager$Stub.onTransact:1132 com.android.server.wm.ActivityTaskManagerService.onTransact:6218 android.os.Binder.execTransactInternal:1215 android.os.Binder.execTransact:1179 <bottom of call stack> 
10-22 15:48:01.243  1285  4684 I ActivityTaskManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x30020000 pkg=com.myapp.app cmp=com.myapp.app/.MainActivity} from uid 10399
10-22 15:48:01.243  1285  4684 E NotificationService: Indirect notification activity start (trampoline) from com.myapp.app blocked
10-22 15:48:01.244  1285  4684 W ActivityTaskManager: Background activity start [callingPackage: com.myapp.app; callingUid: 10399; appSwitchAllowed: true; isCallingUidForeground: false; callingUidHasAnyVisibleWindow: false; callingUidProcState: SERVICE; isCallingUidPersistentSystemProcess: false; realCallingUid: 10399; isRealCallingUidForeground: false; realCallingUidHasAnyVisibleWindow: false; realCallingUidProcState: SERVICE; isRealCallingUidPersistentSystemProcess: false; originatingPendingIntent: null; allowBackgroundActivityStart: false; intent: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x30020000 pkg=com.myapp.app cmp=com.myapp.app/.MainActivity }; callerApp: ProcessRecord{524e055 1428:com.myapp.app/u0a399}; inVisibleTask: false]
10-22 15:48:01.244  1285  4684 D ActivityTaskManager: TaskLaunchParamsModifier:task=null activity=ActivityRecord{7c5b2f5 u0 com.myapp.app/.MainActivity display-from-launchedFrom=0 display-id=0 display-windowing-mode=1 suggested-display-area=DefaultTaskDisplayArea@21040948
10-22 15:48:01.244  1285  4684 D ActivityTaskManager: TaskLaunchParamsModifier:task=Task{8baa509 #12911 type=standard A=10399:com.myapp.app U=0 visible=false mode=fullscreen translucent=true sz=1} activity=ActivityRecord{7c5b2f5 u0 com.myapp.app/.MainActivity t-1} display-from-task=0 display-id=0 display-windowing-mode=1 suggested-display-area=DefaultTaskDisplayArea@21040948 non-freeform-display display-area=DefaultTaskDisplayArea@21040948 maximized-bounds

from cordova-plugin-local-notifications.

rafaellop avatar rafaellop commented on June 21, 2024

@DavidTalevski I use your fork because it's most recent and the issue occurs in your fork as well. The log cat error is Indirect notification activity start (trampoline) from com.myapp.app blocked and the issue is described with a solution in the link given above. I checked the builder.java sources but I don't feel enough good to modify that and I noticed there's no reference to the NotificationTrampolineActivity which is the source of the problems as described in the link.

from cordova-plugin-local-notifications.

DavidTalevski avatar DavidTalevski commented on June 21, 2024

Currently I don't have an android 12 phone available, nor can I simulate one, in order to reproduce the issue and implement the fix. I might be able to get my hands on one next week. If someone implements the fix I will be more than happy to include it in my fork.

from cordova-plugin-local-notifications.

rafaellop avatar rafaellop commented on June 21, 2024

@bhandaribhumin I'll try but from what I have see in the repo your fork also doesn't refer the trampoline so I don't expect it works, but I'll try just to confirm that.

Update: Same thing and the same error using your fork. Sorry.

from cordova-plugin-local-notifications.

rafaellop avatar rafaellop commented on June 21, 2024

Currently I don't have an android 12 phone available, nor can I simulate one, in order to reproduce the issue and implement the fix. I might be able to get my hands on one next week.

Please take a look when you have the v12 phone. Thank you.

from cordova-plugin-local-notifications.

Filavision avatar Filavision commented on June 21, 2024

I realized that when I closed the app with the back button navigator.app.exitApp();, clicking on the notification opens the app. If I just push the app to the background or close the app completely, clicking the notification doesn't work.

from cordova-plugin-local-notifications.

bevinGithub avatar bevinGithub commented on June 21, 2024

@rafaellop please use my fork version https://github.com/bhandaribhumin/cordova-plugin-local-notification-12, this version includes all latest fixes and also compatible with sdk 30,31,32 and 33 as well. Please let me know if you found any issues.

Also use this method to request permission https://github.com/bhandaribhumin/cordova-plugin-local-notification-12#setdummynotification

This plugin also available on npm https://www.npmjs.com/package/cordova-plugin-local-notification-12

Hi Rafellop
Does your fix also include the triggering of events e.g onTrigger also last local notifcation for android 12 did not have events or were not functional.

from cordova-plugin-local-notifications.

rafaellop avatar rafaellop commented on June 21, 2024

Currently I don't have an android 12 phone available, nor can I simulate one, in order to reproduce the issue and implement the fix. I might be able to get my hands on one next week. If someone implements the fix I will be more than happy to include it in my fork.

@DavidTalevski have you maybe managed to put your hands on an Android 12 device to verify that?

from cordova-plugin-local-notifications.

bevinGithub avatar bevinGithub commented on June 21, 2024

Currently I don't have an android 12 phone available, nor can I simulate one, in order to reproduce the issue and implement the fix. I might be able to get my hands on one next week. If someone implements the fix I will be more than happy to include it in my fork.

@DavidTalevski have you maybe managed to put your hands on an Android 12 device to verify that?

Hi Rafaellop.

I am using local notifications and the local notifications 12 is not supporting the events subscription, are you able to resolve this on your fork also? I need the event onTrigger on the local notifications. The code below works on lower version of the plugin are you able to set this up on your fork.

onDeviceReady() {
this.localNotifications.on('trigger').subscribe((test: any) => {
console.log('Trigger' + JSON.stringify(test));
});
}

from cordova-plugin-local-notifications.

bevinGithub avatar bevinGithub commented on June 21, 2024

@rafaellop please use my fork version https://github.com/bhandaribhumin/cordova-plugin-local-notification-12, this version includes all latest fixes and also compatible with sdk 30,31,32 and 33 as well. Please let me know if you found any issues.

Also use this method to request permission https://github.com/bhandaribhumin/cordova-plugin-local-notification-12#setdummynotification

This plugin also available on npm https://www.npmjs.com/package/cordova-plugin-local-notification-12
Hi Bhandaribhumin

Are you able to subscribe to events on your fork version?. I'm using this plugin and the android 12 is not subscribing to events onTrigger. Your assistance will be much appreciated.

from cordova-plugin-local-notifications.

rafaellop avatar rafaellop commented on June 21, 2024

No event works properly.

from cordova-plugin-local-notifications.

bevinGithub avatar bevinGithub commented on June 21, 2024

I have installed this fork link https://github.com/bhandaribhumin/cordova-plugin-local-notification-12 last week, l can assure you the events function call below does not register when the Local notification is triggered. Please sent me the right fork link of the local notifications l can reinstall a new one.

onDeviceReady() {
this.localNotifications.on('trigger').subscribe((test: any) => {
console.log('Trigger' + JSON.stringify(test));
});
}

Below is my package JSON
"cordova-plugin-file-transfer": "git+https://github.com/apache/cordova-plugin-file-transfer.git",
"cordova-plugin-ionic-keyboard": "^2.2.0",
"cordova-plugin-ionic-webview": "^4.2.1",
"cordova-plugin-local-notification-12": "git+https://github.com/bhandaribhumin/cordova-plugin-local-notification-12.git",
"cordova-plugin-media": "^6.1.0",
"cordova-plugin-native-ringtones": "^0.2.5",
"cordova-plugin-nativeaudio": "^3.0.9",
"cordova-plugin-splashscreen": "^5.0.4",

from cordova-plugin-local-notifications.

rafaellop avatar rafaellop commented on June 21, 2024

But I just told you that no event works properly.

from cordova-plugin-local-notifications.

bevinGithub avatar bevinGithub commented on June 21, 2024

My apologies of the misinterpretation of your comment, the events is this something in progress or there is no hope on the plugin?

from cordova-plugin-local-notifications.

bevinGithub avatar bevinGithub commented on June 21, 2024

Hi Powowbox.

Does your fix also include other events e.g ontrigger code below.
onDeviceReady() {
this.localNotifications.on('trigger').subscribe((test: any) => {
console.log('Trigger' + JSON.stringify(test));
});
}

from cordova-plugin-local-notifications.

powowbox avatar powowbox commented on June 21, 2024

Hi bevinGithub,
I've done at test on android 12 by running

cordova.plugins.notification.local.schedule({id: 3, text: "xxxx", triggerInApp: true, trigger: {at: new Date(new Date().getTime() + 5000)}})

the trigger event is correctly raised and received in
cordova.plugins.notification.local.on('trigger', (args) => console.log('===>', args));

The click event works also correctly.

from cordova-plugin-local-notifications.

bevinGithub avatar bevinGithub commented on June 21, 2024

Hi Powowbox.

I am using ionic l will try install your version and test it thanks very much for the response.

i have install your version with the command below:
ionic cordova plugin add https://github.com/powowbox/cordova-plugin-local-notification-12.git

How do l import the cordova plugin in ionic for the same pluginin documentation is like below
import { LocalNotifications } from '@awesome-cordova-plugins/local-notifications/ngx';

from cordova-plugin-local-notifications.

powowbox avatar powowbox commented on June 21, 2024

Sorry, I can’t help I don’t use awesome-cordova-plugins.

from cordova-plugin-local-notifications.

bevinGithub avatar bevinGithub commented on June 21, 2024

Im just showing you how l import awesome-cordova-plugins. I want to know how to import your cordova plugin in ionic.

from cordova-plugin-local-notifications.

powowbox avatar powowbox commented on June 21, 2024

use cordova plugin add https://github.com/powowbox/cordova-plugin-local-notification-12.git --save --noregistery. Then check in your package.json, you must find a line like "cordova-plugin-local-notification-12": "git+https://github.com/powowbox/cordova-plugin-local-notification-12.git", in the dependencies object and in the plugins object you must find "cordova-plugin-local-notification-12": {}.

from cordova-plugin-local-notifications.

bevinGithub avatar bevinGithub commented on June 21, 2024

Hi powowbox.

I have managed to to get your fork working now, the issue was to get the var reference of the cordova in ionic and call the function as you supplied before, thanks for your assistance the notifications events are working now.

from cordova-plugin-local-notifications.

bhandaribhumin avatar bhandaribhumin commented on June 21, 2024

Hi @powowbox Thanks for the fix, I've added your fix to my branch. Can you please take a look if everything looks goot to you then I'll merge to main. Thanks a lot, cheers.

from cordova-plugin-local-notifications.

bevinGithub avatar bevinGithub commented on June 21, 2024

hi Powowbox.

The setting triggerInapp does make the plugin subscribe to events but stops the notification being displayed in the phones default notifications area even if the foreground setting is true. Is there way to show the notification popup if the app is closed as the phone just vibrates and the light is on and plays the sound and no popup of notification these are the settings l have
cordova.plugins.notification.local.schedule({
id: 3,
text: 'xxxx',
foreground: true,
lockscreen: true,
priority: true,
triggerInApp: true,
data: { name: 'Bevin', surname: 'Masevenza', cell: '0734913786' },
trigger: {at: new Date(new Date().getTime() + 5000)}
});

from cordova-plugin-local-notifications.

powowbox avatar powowbox commented on June 21, 2024

@bhandaribhumin Hi, thanks for merging my changes. I haven't done any test on your merge, I only look at the merge. It sounds good.

from cordova-plugin-local-notifications.

powowbox avatar powowbox commented on June 21, 2024

Hi, @bevinGithub
`
// Show notification if we should (triggerInApp is false)

    // or if we can't trigger in the app due to:

    //   1.  No autoLaunch configured/supported and app is not running.

    //   2.  Any SDK >= Oreo is asleep (must be triggered here)

    boolean didShowNotification = false;

    if (!options.triggerInApp() || (!autoLaunch && !checkAppRunning())
    ) {

        didShowNotification = true;

        notification.show();

    }

`

Following the code above, it seems the behaviour you describe corresponds to the expected one.
If you enable the trigger option, when the app is visible, it's its responsability to display the notification to the user, so no need to display it in the notification center.
If the app is closed, since the app cannot display the notification, it must be displayed in the notification center.

There is one last case, that sounds to not be correctly handled: when the app is in background, the notification isn't displayed in the notification center even if the app cannot displayed show it to the user. I can try to fix it.

from cordova-plugin-local-notifications.

bevinGithub avatar bevinGithub commented on June 21, 2024

hi Powowbox.

If i add the triggerInApp: true, the events are subscribing but the app is not showing the Notification in the notifications center.
I need to show the notifications in the notification center and still get the trigger events to subscribe which is not working if the setting triggerInApp: false, when true the subscribing to events works as l have another function to play audios or custo music file when the trigger happens.

if triggerInApp: false, l want the subscribing to event onTrigger to still work as it is currently only working when triggerInApp: true, only
Hope you understand what l am saying.

from cordova-plugin-local-notifications.

powowbox avatar powowbox commented on June 21, 2024

If I understand well, if triggerInApp is set to true, you want to display the notification in any case, the app is visible or not. It's a very specific need. You can make your own fork. To have the expected behaviour, in the file AbstractNotificationReceiver, change the condition in

`
if (!options.triggerInApp() ||

        (!autoLaunch && !checkAppRunning())

    ) {

        didShowNotification = true;

        notification.show();

    }

`

Remove !options.triggerInApp() from the test and you should have what you want.

from cordova-plugin-local-notifications.

bevinGithub avatar bevinGithub commented on June 21, 2024

Hi Powowbox.

My programming skills are only limited to ionic angular i have zero skills on modifying plugins.

If l remove the triggerInApp: Yes l am not able to subscribe to event onTrigger, the below code will not work if triggerInApp is false or is removed completely.

onDeviceReady() {
this.localNotifications.on('trigger').subscribe((test: any) => {
console.log('Trigger' + JSON.stringify(test));
});
}

from cordova-plugin-local-notifications.

bhandaribhumin avatar bhandaribhumin commented on June 21, 2024

Hello @bevinGithub you can use this method to prompt for runtime permission.

from cordova-plugin-local-notifications.

bevinGithub avatar bevinGithub commented on June 21, 2024

Hi Bhandaribhumin.

I am looking to just get trigger events after the notification triggers l subscribe to the event onTrigger to play custom audios or sound.
onDeviceReady() {
this.localNotifications.on('trigger').subscribe((test: any) => {
console.log('Trigger' + JSON.stringify(test));
});
}

if i have the code below, triggerInApp: true does make evet subscrition happen if l set it to false the trigger events don't work
I need trigger events to work at the same time the notification gets displayed in the notifications center.
cordova.plugins.notification.local.schedule({
id: 3,
text: 'xxxx',
foreground: true,
lockscreen: true,
priority: true,
triggerInApp: true,
data: { name: 'Bevin', surname: 'Masevenza', cell: '0734913786' },
trigger: {at: new Date(new Date().getTime() + 5000)}
});

from cordova-plugin-local-notifications.

Filavision avatar Filavision commented on June 21, 2024

Hi @powowbox Thanks for the fix, I've added your fix to my branch. Can you please take a look if everything looks goot to you then I'll merge to main. Thanks a lot, cheers.

Hey! Click on the notification doesn't open my App. I have a "refresh" button in my notification to update the notification with a random number. Clicking the refresh button open the app but clicking the notification does nothing. The app should open when clicking the notification and should not open but update the notification text when clicking the refresh button.
cordova.plugins.notification.local.addActions('refresh',[{id:'refresh',title:'Refresh'}]); cordova.plugins.notification.local.on('refresh',function(){cordova.plugins.notification.local.update({id:1,title:'Title',text:'Random number: '+rand(0,100)});}); cordova.plugins.notification.local.schedule({id:1,title:'Title',text:'Random number: '+rand(0,100),sound:false,vibrate:false,wakeup:false,priority:-1,actions:'refresh',foreground:true,lockscreen:true,sticky:true,smallIcon:'res://notification_icon'});

from cordova-plugin-local-notifications.

fquirin avatar fquirin commented on June 21, 2024

Some info to actually explain why "tap on notifications" does not open the app in Android 12:
It is because of Notification trampoline restrictions. If you deactivate the flag NOTIFICATION_TRAMPOLINE_BLOCK for your app in Android developer options (e.g. on Emulator) it will work again ... obviously this is not a solution, just a test.
The issue seems to be that the PendingIntent attached to the click (the plugin has a ClickReceiver class) is a service not an activity and thus is not allowed to trigger context.startActivity() anymore. I'm currently banging my head against a wall to find how why Google would mess up the API like this 🤕.

@powowbox I see you've refactored AbstractClickReceiver to use an activity instead of a service. That was exactly what I was planning to try next 👍 . Will check it out to see what else you've changed 🙂 .

from cordova-plugin-local-notifications.

fquirin avatar fquirin commented on June 21, 2024

Hi, my fork is fully functional on android 12 and 13. Just be careful, if you use action buttons in your notifications. In this case, I voluntarily disable the click on the notification to avoid the user clicks on notification before discovering the buttons.

Saw that and I think it makes total sense 👍 . Any other breaking changes?
Code looks good so far, I'll probably replace my own fork with your one 🙂

[EDIT] One more question @powowbox : The previous IntentService could run in the background because ... well it was a service 😅 . Did you notice any issues due to the replacement with an activity?

from cordova-plugin-local-notifications.

fquirin avatar fquirin commented on June 21, 2024

I've merged all changes from @timkellypa, @bhandaribhumin and @powowbox into my own fork, so we could create a PR for the original repository. But since there are so many changes now, I doubt this PR would ever be accepted 😅

from cordova-plugin-local-notifications.

bevinGithub avatar bevinGithub commented on June 21, 2024

Hi guys are you able to do a fix on IOS for local notifications? events triggering when app is in the background is not subscribing to events IOS 16

from cordova-plugin-local-notifications.

fquirin avatar fquirin commented on June 21, 2024

@bevinGithub I'm not familiar with the iOS code, sorry.

from cordova-plugin-local-notifications.

alitalaee avatar alitalaee commented on June 21, 2024

Hi powowbox.

I have managed to to get your fork working now, the issue was to get the var reference of the cordova in ionic and call the function as you supplied before, thanks for your assistance the notifications events are working now.

How did you do that please?

from cordova-plugin-local-notifications.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.