ionic-team / ionic-team/capacitor-plugins
[Bug]: (Push-Notification) Registration listener returns old Token if register is called immediatly after unregister
- Dominant language
- Java
- Stars
- 678
- Forks
- 685
- Avg merge
- 4d 22h
- Merged PRs (30d)
- 3
Description
### Capacitor Version
Capacitor Doctor
Latest Dependencies:
@capacitor/cli: 8.5.1
@capacitor/core: 8.5.1
@capacitor/android: 8.5.1
@capacitor/ios: 8.5.1
Installed Dependencies:
@capacitor/core: 8.4.0
@capacitor/android: 8.4.0
@capacitor/cli: 8.4.0
@capacitor/ios: 8.4.0
@capacitor/push-notifications: 8.0.3
[success] Android looking great! 👌
[error] Xcode is not installed
### Other API Details
```Shell
npm --version output: 11.12.1
node --version output: 24.16.0
```
### Platforms Affected
- [ ] iOS
- [x] Android
- [ ] Web
### Current Behavior
If we call register immediatly after having called unregister, we get the already existing token again.
This behaviour can be reproduced every second time this sequence is called.
```
await PushNotifications.addListener('registration', (token: Token) => {...});
await PushNotifications.unregister();
await PushNotifications.register();
```
### Expected Behavior
We get a new Token everytime we call `await PushNotifications.register();`
### Project Reproduction
https://stackblitz.com/edit/angular-4zsdop-napdpb7a?file=src%2Fapp%2Fapp.component.ts,src%2Fapp%2Fapp.component.html
### Additional Information
The reproduction is only theoretical since a real setup requires a running Android System.
In our App we would like to give the User the option to exchange the existing token with a new one.
Contributor guide
Research direction
Start with the linked StackBlitz reproduction and run it on Android, focusing on the addListener → unregister → register sequence. Then trace the Android implementation of @capacitor/push-notifications and its registration event path. Done means each register call after unregister delivers a newly issued token rather than the previous token, with coverage for the alternating behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java, javascript
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100