cordova-plugin-local-notifications icon indicating copy to clipboard operation
cordova-plugin-local-notifications copied to clipboard

Android 12 (SDK 31+): Tap on notifications only opens app when notifications are grouped.

Open fragfeaster777 opened this issue 2 years ago • 50 comments

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:
  • cordova-plugin-local-notification-12 0.1.3 "LocalNotification"
  • cordova-plugin-badge-fix 0.8.10 "Badge"
  • Platform: Android
  • OS version: 12
  • Device manufacturer / model: n/a
  • Cordova version (cordova -v): 11.0.0
  • Cordova platform version (cordova platform ls): android 10.1.1

Expected 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

  1. When a single notification is triggered, tap on it. App is not opened.
  2. When 2 or 3 notifications are triggered, tapping on any of them doesn't open the app.
  3. When notifications are grouped, tapping on any of them opens up the app.

Context

Open app when tapping notification

Debug logs

NotificationService: Indirect notification activity start (trampoline) from com.xxx.xxx blocked

fragfeaster777 avatar Oct 19 '22 18:10 fragfeaster777

Related:

https://github.com/wix/react-native-notifications/issues/884 https://github.com/katzer/cordova-plugin-local-notifications/issues/1989 https://github.com/katzer/cordova-plugin-local-notifications/issues/1970

fragfeaster777 avatar Oct 19 '22 18:10 fragfeaster777

I have the same issue...

Filavision avatar Oct 20 '22 16:10 Filavision

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

rafaellop avatar Oct 22 '22 12:10 rafaellop

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

rafaellop avatar Oct 22 '22 12:10 rafaellop

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

DavidTalevski avatar Oct 22 '22 13:10 DavidTalevski

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.

Filavision avatar Oct 22 '22 13:10 Filavision

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?

DavidTalevski avatar Oct 22 '22 13:10 DavidTalevski

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

Filavision avatar Oct 22 '22 13:10 Filavision

@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.

rafaellop avatar Oct 22 '22 14:10 rafaellop

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 avatar Oct 22 '22 14:10 DavidTalevski

@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 avatar Oct 22 '22 19:10 bhandaribhumin

@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.

rafaellop avatar Oct 23 '22 06:10 rafaellop

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.

rafaellop avatar Oct 24 '22 07:10 rafaellop

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.

Filavision avatar Oct 24 '22 09:10 Filavision

@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.

bevinGithub avatar Oct 24 '22 19:10 bevinGithub

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?

rafaellop avatar Oct 31 '22 07:10 rafaellop

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)); }); }

bevinGithub avatar Nov 01 '22 11:11 bevinGithub

@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.

bevinGithub avatar Nov 01 '22 11:11 bevinGithub

No event works properly.

rafaellop avatar Nov 01 '22 13:11 rafaellop

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",

bevinGithub avatar Nov 01 '22 13:11 bevinGithub

But I just told you that no event works properly.

rafaellop avatar Nov 01 '22 14:11 rafaellop

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

bevinGithub avatar Nov 01 '22 14:11 bevinGithub

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.

powowbox avatar Nov 01 '22 19:11 powowbox

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)); }); }

bevinGithub avatar Nov 01 '22 20:11 bevinGithub

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.

powowbox avatar Nov 01 '22 21:11 powowbox

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';

bevinGithub avatar Nov 02 '22 05:11 bevinGithub

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

powowbox avatar Nov 02 '22 07:11 powowbox

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

bevinGithub avatar Nov 02 '22 07:11 bevinGithub

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": {}.

powowbox avatar Nov 02 '22 09:11 powowbox

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.

bevinGithub avatar Nov 02 '22 12:11 bevinGithub