Giter Club home page Giter Club logo

Comments (5)

NeilCresswell avatar NeilCresswell commented on August 16, 2024

This has been working fine for us in a production app on real Android 13 devices. FWIW we're targeting 32 but have the same uses-permission set in config.xml. You perhaps might want to consider also sharing the code where you're calling the plugin to check or request this permission.

Our code is effectively using .checkPermission (then .requestPermission as appropriate) when the registration event fires for our push notification service. From memory, (so could be mistaken here,) the first time the app runs, you don't need permission so you likely won't get a dialog but the next time it fires you should.

from cordova-plugin-android-permissions.

firleaf avatar firleaf commented on August 16, 2024

Here is a bare bones example of what I'm doing.

const onRegistration = async (data) => {
    console.log("onRegistration", data);

    const perm = cordova.plugins.permissions;
    const { hasPermission } = await new Promise((resolve, reject) => perm.checkPermission(perm.POST_NOTIFICATIONS, resolve, reject));
    if (!hasPermission) {
        const value = await new Promise((resolve, reject) => perm.requestPermissions([perm.POST_NOTIFICATIONS], resolve, reject));
        console.log(value); // unknown error :(
    }
}

const onDeviceReady = async () => {
    document.getElementById('deviceready').classList.add('ready');

    const push = PushNotification.init({
        android: {}
    });
    push.on("registration", onRegistration);
    push.on("notification", console.log);
}

document.addEventListener('deviceready', onDeviceReady, false);

This is using @havesource/cordova-plugin-push as the notification plugin. Somehow I now get a dialog when starting the app the second time, but it closes itself after about a second. Any idea why that might be happening?

from cordova-plugin-android-permissions.

NeilCresswell avatar NeilCresswell commented on August 16, 2024

Probably not related but in case it helps... We're using the same plugin for our push notifications, but installing via cordova plugin add github:havesource/cordova-plugin-push to make sure we get v4 instead of v3 via cordova plugin add @havesource/cordova-plugin-push since v3 doesn't seem to properly support Android 12 or 13.

For the permissions plug in, might be worth checking you're using the latest v1.1.4, which was published a couple of weeks ago? That's the first version which supports the POST_NOTIFICATIONS permission. I imagine you are but always worth mentioning just in case.

Not sure what else to suggest looking at. Maybe experiment with targeting SDK 32, as I know that's working for us. We didn't go with 33 since it was too new. Didn't want to be bleeding edge. Does work for us on Android 13 devices such as a Pixel 6.

from cordova-plugin-android-permissions.

NeilCresswell avatar NeilCresswell commented on August 16, 2024

Another quick thought: We're using .requestPermission (singular) - and didn't try a list with .requestPermissions as you're doing here. As you're just looking to add a single permission, you could try changing that to .requestPermission and see if that is a good workaround.

from cordova-plugin-android-permissions.

firleaf avatar firleaf commented on August 16, 2024

You're right, it's probably not related. Thanks for all the suggestions though. Closing this for now.

from cordova-plugin-android-permissions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.