Giter Site home page Giter Site logo

Comments (10)

santhu180485 avatar santhu180485 commented on July 20, 2024 1

@kristopolous , I am using this plugin and when I select the "Deny" option, the app just gets closed/crashed.
Am I missing anything?

from cordova-plugin-android-permissions.

hoongoon86 avatar hoongoon86 commented on July 20, 2024

I'm not here for solution but, isn't it natural to have success callback if requestPermission has been called successfully?
If you want to check whether the permission had been granted, we have hasPermission (as you already know).

from cordova-plugin-android-permissions.

NeoLSN avatar NeoLSN commented on July 20, 2024

Is the value of p.hasPermission false if a user decided not to grant the permission?

from cordova-plugin-android-permissions.

kristopolous avatar kristopolous commented on July 20, 2024

Quoting: https://developer.android.com/training/permissions/requesting.html

When the system asks the user to grant a permission, the user has the option of telling the system not to ask for that permission again. In that case, any time an app uses requestPermissions() to ask for that permission again, the system immediately denies the request. The system calls your onRequestPermissionsResult() callback method and passes PERMISSION_DENIED, the same way it would if the user had explicitly rejected your request again. This means that when you call requestPermissions(), you cannot assume that any direct interaction with the user has taken place.

What this means is that this use-case could be valid under those conditions. I however, believe it's happening in more than just this instance ... let me get back with a confirmation soon.

from cordova-plugin-android-permissions.

kristopolous avatar kristopolous commented on July 20, 2024

Also, this doesn't preclude including things in the manifest in addition to asking explicitly. Quoting the same link above:

On all versions of Android, your app needs to declare both the normal and the dangerous permissions it needs in its app manifest, as described in Declaring Permissions

from cordova-plugin-android-permissions.

kristopolous avatar kristopolous commented on July 20, 2024

So for me at least, after manually adding this line to my AndroidManifest.xml (for in this case camera, since this seems to be the big pain point)

 <uses-permission android:name="android.permission.CAMERA" />

And then rebuilding, I can

  • request the permission multiple times
  • get the fail case if I tick "never ask again".

This appears to be the right result. This is with

<plugin name="cordova-plugin-camera" spec="~2.3.0" />

There is a PR that is outstanding that will do this: apache/cordova-plugin-camera#228 ... once that closes this probably doesn't need to be done any more.

Until then it looks like this is needed. Bummer...

from cordova-plugin-android-permissions.

kristopolous avatar kristopolous commented on July 20, 2024

As far as detecting if the user had done the "never ask again" option probably the only feasible way to do it (since android doesn't tell you) would be something heuristic like this:

var beforeRequest = new Date();
window.cordova.plugins.permissions.requestPermission(
    window.cordova.plugins.permissions.CAMERA, function(m) { 
    if(!m.hasPermission && (new Date() - beforeRequest) < 350) {
      // 350 ms is pretty fast for a user to tap on a deny ... and even if they did
      // this is probably a user error and we should pretend like they didn't see it.
      // either way this should be handling as if the dialog never appeared.
      // In *my* user testing on a moto 3g 2015, I couldn't tap this dialog with a value 
      // less than 554 -and that was with a sincere effort to dismiss it as soon as possible
      // as if it was a game. This implicates there's likely a significant overhead baked in
      // before the dialog even appears
     ...
    }
 }, null);

from cordova-plugin-android-permissions.

jacquesdev avatar jacquesdev commented on July 20, 2024

@NeoLSN - "Is the value of p.hasPermission false if a user decided not to grant the permission?"

Yes it is false even when the dialog is ignored.

from cordova-plugin-android-permissions.

artuska avatar artuska commented on July 20, 2024

When user clicks Deny my app just crashes.

from cordova-plugin-android-permissions.

Truelion avatar Truelion commented on July 20, 2024

cordova plugin does not fire a failure or success callback when requestPermission() is called on the very first install of the apk via USB cable or on emulator or from installing an APK build from disk. It does pop the dialog to request geo permissions fine, I grant it, but it never fires a callback. (?)

When i close the app and reopen, geolocation works, because i previously granted. But on very first install, callbacks for requestPermission() does nothing, so app is at standstill. Does anyone know what it could be? Tried on several phones, all identical behavior.

USING window.cordova.plugins:

requestCordovaPermissions() {
    var self = this;
    window.cordova.plugins.permissions.requestPermission(
        window.cordova.plugins.permissions.ACCESS_FINE_LOCATION,
        function(status) {// <-------never fired
            if (status.hasPermission) {
                alert("permission granted") _ //never seen, even if i granted_
            } else {
                alert("unable to get geo location permissions")
            }
        },
        function(e) {//<------ never fired
            alert("Error : " + e)
        }
    )
}


Snippet from AndroidManifest.xml:
`
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="25" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
`


config.xml:

`
<feature name="Geolocation">
        <param name="android-package" value="org.apache.cordova.GeoBroker" />
    </feature>
    <engine name="android" spec="^6.3.0" />
    <plugin name="cordova-plugin-android-permissions" spec="^1.0.0" />
    <plugin name="cordova-plugin-exclude-files" spec="^0.4.2" />
    <plugin name="cordova-plugin-fullscreen" spec="^1.2.0" />
    <plugin name="cordova-plugin-geolocation" spec="^4.0.1" />
    <plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
`

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.