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

grantPermission never callback when called on Android 11 #819

Closed
gouteru opened this issue Jul 2, 2023 · 1 comment
Closed

grantPermission never callback when called on Android 11 #819

gouteru opened this issue Jul 2, 2023 · 1 comment

Comments

@gouteru
Copy link

gouteru commented Jul 2, 2023

Bug report

CHECKLIST

  • [ ✔️] I have read the issue reporting guidelines

  • [ ✔️] I confirm this is a suspected bug or issue that will affect other users

  • [ ✔️] I have reproduced the issue using the example project or provided the necessary information to reproduce the issue.
  • [ ✔️] I have read the documentation thoroughly and it does not help solve my issue.
  • [ ✔️] I have checked that no similar issues (open or closed) already exist.

Current behavior:

I have read through the readme about grantPermission() and successfully worked on Android 13 device(Pixel6a).
But when I tested on Android 11 device(Sony Xperia10 A001SO), grantPermission() never callback.

Is this only about my case or Xperia10 issue? Can you tell me about other Android <= 12 devices are okay?

Expected behavior:

As documented about Android <= 12, grantPermission should success with return value true.

Steps to reproduce:

Screenshots

Environment information

  • Cordova CLI version
    • cordova -v 12.0.0
  • Cordova platform version
    • cordova platform ls android 12.0.0
  • Plugins & versions installed in project (including this plugin)
    • cordova plugin ls 16.1.0
  • Dev machine OS and version, e.g.
    • OSX
      • sw_vers 13

Runtime issue

  • Device details
    • Android 11 device(Sony Xperia10 A001SO)
  • OS details
    • Android 11

Android build issue:

  • Node JS version
    • node -v
  • Gradle version
    • ls platforms/android/.gradle 16.13.2
  • Target Android SDK version
    • android:targetSdkVersion in AndroidManifest.xml 33
  • Android SDK details
    • sdkmanager --list | sed -e '/Available Packages/q'

Related code:

    getPermissionAsync () {
      return new Promise((resolve, reject) => {
        window.FirebasePlugin.hasPermission((hasPermission) => {
          if (typeof hasPermission === 'boolean') {
            console.log('hasPermission: ', hasPermission)
            resolve(hasPermission)
          } else {
            console.log('hasPermission error: ', hasPermission)
            reject(new Error(hasPermission))
          }
        })
      })
    },
    grantPermissionAsync () {
      return new Promise((resolve, reject) => {
        window.FirebasePlugin.grantPermission((hasPermission) => {
          if (typeof hasPermission === 'boolean') {
            console.log('hasPermission: ', hasPermission)
            resolve(hasPermission)
          } else {
            console.error('hasPermission error: ', hasPermission)
            reject(new Error(hasPermission))
          }
        })
      })
    },

          const permission = await this.getPermissionAsync()
          if (permission === true) {
            console.log('*** push permission OK: ', permission)
            this.isPushSetting = true
            await this.getTokenAsync()
            .then((token) => {
              self.fcmToken = token
              self.fcmTokenInit()
            }).catch((err) => {
              console.error('*** Get Token Error: ', err)
            })
          } else if (permission === false) {
            console.log('*** push permission Denied: ', permission)
            const permissionRetry = await this.grantPermissionAsync() <<<<------ Never callback here
            console.log('permissionRetry: ', permissionRetry)
            if (permissionRetry) {
              this.isPushSetting = true
              await this.getTokenAsync()
                .then((token) => {
                  self.fcmToken = token
                  self.fcmTokenInit()
                }).catch((err) => {
                  console.error('*** Get Token Error: ', err)
                })
            } else {
              this.isPushSetting = permissionRetry
              this.fcmToken = 'denied'
              this.fcmTokenInit()
            }
          }

Console output
No output

Other information:

@Khazbs
Copy link

Khazbs commented Oct 16, 2023

I have the same issue on Android 10 and 12 as well, and supposedly any Android prior to 13. I think a possible workaround would be to check Android version and bypass grantPermission if it is not needed, i.e. on Android < 13.

@dpa99c dpa99c closed this as completed in 6ccd621 Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants