Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): prevent permission dialog appearing when already denied #325

Merged
merged 1 commit into from
Dec 7, 2024

Conversation

erisu
Copy link

@erisu erisu commented Dec 5, 2024

Motivation and Context

Prevent second permission dialog from appearing on second launch if user already selected "Don't allow".

Description

If the user selects "Don't allow" for the push notification permission, it is expected that the notification dialog will not reappear on subsequent launches asking the same question.

It is assumed that the user's decision reflects their intent.

If they made a mistake, they can go to the app settings to manually enable the permission.

Additionally, the unusual behavior of the permission dialog reappearing occurs only on the second launch; on the third or later launches, the dialog does not appear.

The changes in this PR ensure that the decision made by the app user is acknowledged and the permission will not be requested again.

This behavior was achieved by adding a call to shouldShowRequestPermissionRationale before invoking the requestPermissions method, which aligns with the guidance provided in the Android documentation.

Reference: Android Documentation - requestPermissions

Related Issue

n/a

How Has This Been Tested?

  • Built Android app
  • Ran app
  • Click "Don't allow" for the notification permission
  • Close app
  • Open app
  • Confirmed that the dialog does not display again.

Additional Test:

  • Go to app settings
  • Enable notification permission
  • Re-open app
  • Confirm registration completed

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@erisu erisu added bug Something isn't working android Related to the Android platform labels Dec 5, 2024
@erisu erisu added this to the 5.0.1 milestone Dec 5, 2024
@erisu erisu merged commit 82776b4 into master Dec 7, 2024
7 checks passed
@erisu erisu deleted the fix/android-double-permission-dialog branch December 7, 2024 15:35
@maxs15
Copy link

maxs15 commented Dec 9, 2024

@erisu I'm receiving the compilation error "PushPlugin.kt:616:13 Unresolved reference: ActivityCompat" since this commit has been merged.

It looks like the import of "androidx.core.app.ActivityCompat" is missing?

@erisu
Copy link
Author

erisu commented Dec 10, 2024

@maxs15 Thank you for catching this.

Everything was working when tested but I guess I forgot to copy over the import line for the PR.

I created a fix #331.
I will merge and release 5.0.2 in a couple of minutes.

Copy link

github-actions bot commented Jan 1, 2025

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
android Related to the Android platform bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants