Closed fragfeaster777 closed 1 month ago
I have the same issue...
The issue and solution is described here: https://proandroiddev.com/notification-trampoline-restrictions-android12-7d2a8b15bbe2
@bhandaribhumin or @DavidTalevski could you look please at it?
Can you try my fork and confirm if the issue persists there?
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.
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?
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
@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.
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.
@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
@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.
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.
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.
@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.
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?
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)); }); }
@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.
No event works properly.
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",
But I just told you that no event works properly.
My apologies of the misinterpretation of your comment, the events is this something in progress or there is no hope on the plugin?
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.
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)); }); }
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.
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';
Sorry, I can’t help I don’t use awesome-cordova-plugins.
Im just showing you how l import awesome-cordova-plugins. I want to know how to import your cordova plugin in ionic.
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": {}
.
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.
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.
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)} });
@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.
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.
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.
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.
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)); }); }
Hello @bevinGithub you can use this method to prompt for runtime permission.
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)} });
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'});
@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’.
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 🙂 .
@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.
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?
@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.
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 😅
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
@bevinGithub I'm not familiar with the iOS code, sorry.
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?
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!
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
cordova -v
): 11.0.0cordova platform ls
): android 10.1.1Expected Behavior
On Android 12, after an app is killed or in the background, tapping on a notification does not open the app. Adb logcat shows the following:
NotificationService: Indirect notification activity start (trampoline) from com.xxx.xxx blocked
The same happens when 2 and 3 notifications from the same app have been queued up.
However, when more than 3 notifications are queued and these notifications are grouped together, tapping on any of these notifications opens up the app.
Happy to do any testing to further debug.
Actual Behavior
App should open with tapping a single notification
Steps to Reproduce
Context
Open app when tapping notification
Debug logs
NotificationService: Indirect notification activity start (trampoline) from com.xxx.xxx blocked