nativescript-community / perms

An unified permissions API for NativeScript on iOS and Android.
https://nativescript-community.github.io/perms/
Apache License 2.0
12 stars 9 forks source link

Utils.android.getApplicationContext().checkSelfPermission('storage') always return false #28

Closed AAlex-11 closed 5 months ago

AAlex-11 commented 5 months ago

Manifest

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"  />
<uses-permission android:name="android.permission.INTERNET"/>
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Which platform(s) does your issue occur on?

  _osVersion: "11"
 _sdkVersion: "30"

Nativescript version

"@nativescript/core": "~8.6.0",

Error

  Utils.android.getApplicationContext().checkSelfPermission('storage')

MyVault-06062024_141556_1

and, of course, any attempt to write produced error

  ERROR Error: Uncaught (in promise): Error: java.io.FileNotFoundException: /storage/emulated/0/Documents/2024-06-06-11:08:38.json: open failed: EPERM (Operation not permitted)
farfromrefug commented 5 months ago

@AAlex-11 what s the relation between Utils.android.getApplicationContext().checkSelfPermission('storage') and this plugin? :

Please read the readme of the plugin

AAlex-11 commented 5 months ago

Hi, @farfromrefug, plugins return never-ask-again

MyVault-06062024_134149_1

Therefore I take a look to code @nativescript/core/utils

  check(permission: string | string[]) {
     const context = Utils.android.getApplicationContext();
    let result = true;
    const granted = android.content.pm.PackageManager.PERMISSION_GRANTED;
     if (!Array.isArray(permission)) {
         permission = [permission];
    }
    if (this.getAndroidSDK() < this.MARSHMALLOW) {
        permission.forEach((p) => (result = result && context.checkPermission(p, android.os.Process.myPid(), android.os.Process.myUid()) === granted));
    } else {
        permission.forEach((p) => (result = result && context.checkSelfPermission(p) === granted));
   }
   return result;
}

and trace result. What wrong? at any case -

MyVault-06062024_124317_1

despite all permissions I have in Manifest of my application.

AAlex-11 commented 5 months ago

@farfromrefug and about readme. I can not see example - how to require permission to write to Android (Angular). Where is placed that readme? Link I expected https://nativescript-community.github.io/perms/ - has no example for Android, isn't it?

farfromrefug commented 5 months ago

@AAlex-11 everything you need to know about the plugin api is in the readme. But you need to read and look at android doc to correctly setup your project as explained here https://github.com/nativescript-community/perms?tab=readme-ov-file#android-notes Android permissions are complicated. Not everything can be explained here and I purposely dont add all so that users take the time to read native docs. Never ask again means android is not OK with your project setup(related to running android version) and won't allow you to request permission