NativeScript / NativeScript

⚡ Empowering JavaScript with native platform APIs. ✨ Best of all worlds (TypeScript, Swift, Objective C, Kotlin, Java, Dart). Use what you love ❤️ Angular, Capacitor, Ionic, React, Solid, Svelte, Vue with: iOS (UIKit, SwiftUI), Android (View, Jetpack Compose), Dart (Flutter) and you name it compatible.
https://nativescript.org
MIT License
24.26k stars 1.64k forks source link

Problem accessing file in Downloads directory on Android 12 #10054

Closed ray007 closed 1 year ago

ray007 commented 2 years ago

Issue Description

To import and export config files (in json format), the Downloads directory seemed to be a good location so far.

With our new test device with Android 12, that suddenly does not work anymore. Trying to read or write a file there runs into an EACCESS error.

Looking in settings under App permissions, my app is allowed Files and media, but it's set to media only and requires manually setting to Allow management of all files before I can import config files from the downloads directory again.

I have even added a line

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

to my AndroidManifest.xml file and an attribute android:requestLegacyExternalStorage="true" to its application tag, but nothing seems to help so far.

Reproduction

No response

Relevant log output (if applicable)

No response

Environment

OS: Windows 10 10.0.19042
CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
Shell: Not Found
node: 16.17.1
npm: 8.19.2
nativescript: Not Found

# android
java: Not Found
ndk: Not Found
apis: 28, 29, 30, 31, 32
build_tools: 29.0.2, 32.0.0, 32.1.0
system_images: Not Found

# ios
xcode: Not Found
cocoapods: Not Found
python: Not Found
python3: Not Found
ruby: Not Found
platforms: Not Found

Dependencies

"dependencies": {
  "@akylas/nativescript-checkbox": "^2.0.5",
  "@bradmartin/nativescript-urlhandler": "^2.0.1",
  "@nativescript-community/ble": "^3.1.8",
  "@nativescript-community/preferences": "^1.3.0",
  "@nativescript-community/systemui": "^1.1.8",
  "@nativescript-community/ui-collectionview": "^4.0.62",
  "@nativescript-community/ui-material-bottomnavigationbar": "^7.0.28",
  "@nativescript-community/ui-material-bottomsheet": "^7.0.28",
  "@nativescript-community/ui-material-button": "^7.0.28",
  "@nativescript-community/ui-material-progress": "^7.0.28",
  "@nativescript-community/ui-share-file": "^1.2.3",
  "@nativescript/appavailability": "^2.0.0",
  "@nativescript/appversion": "^2.0.0",
  "@nativescript/core": "~8.3.5",
  "@nativescript/secure-storage": "^3.0.0",
  "@nativescript/theme": "^3.0.2",
  "@nota/nativescript-webview-ext": "^8.0.2",
  "@prabudevarrajan/filepicker": "^2.0.0",
  "@sergeymell/nativescript-svg": "^1.1.2",
  "buffer": "^6.0.3",
  "crypto-browserify": "^3.12.0",
  "debounce": "^1.2.1",
  "http-auth-client": "^0.4.1",
  "js-base64": "^3.7.2",
  "js-pkce": "^1.2.1",
  "nativescript-cscreenshot": "^1.2.1",
  "nativescript-drop-down": "^6.0.2",
  "nativescript-inappbrowser": "^3.2.0",
  "nativescript-permissions": "^1.3.12",
  "nativescript-ui-listview": "^10.2.6",
  "nativescript-ui-sidedrawer": "^10.0.2",
  "nativescript-videoplayer": "^5.0.1",
  "nativescript-vue": "^2.9.3",
  "url-search-params-polyfill": "^8.1.1"
},
"devDependencies": {
  "@babel/core": "^7.19.3",
  "@babel/preset-env": "^7.19.3",
  "@nativescript/android": "8.3.1",
  "@nativescript/ios": "8.3.3",
  "@nativescript/types": "~8.3.1",
  "@nativescript/webpack": "~5.0.8",
  "babel-loader": "^8.2.5",
  "nativescript-vue-template-compiler": "^2.9.3",
  "node-sass": "^7.0.3",
  "typescript": "^4.8.4",
  "vue-loader": "^17.0.0"
}

Please accept these terms

rigor789 commented 2 years ago

Storage in Android is very picky & restrictive... android:requestLegacyExternalStorage="true" is ignored on API 30+: image

Here are some resources that might get you going: https://developer.android.com/training/data-storage/use-cases https://developer.android.com/training/data-storage/manage-all-files

Seems like directing the users to the System Settings to change the access type is the expected approach based on the 2nd link above:

Use the ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION intent action to direct users to a system settings page where they can enable the following option for your app: Allow access to manage all files.

To determine whether your app has been granted the MANAGE_EXTERNAL_STORAGE permission, call [Environment.isExternalStorageManager()](https://developer.android.com/reference/android/os/Environment#isExternalStorageManager()).

ray007 commented 2 years ago

@rigor789 thanks for your information, even if I do not like the result.

In the end, accessing files in the shared Downloads folder will not easily work anymore, and we will need platform specific code to so so. Will nativescript provide some helpers to do that, or will everybody have to implement those in their own app?

ray007 commented 1 year ago

Is that a fixed or won't fix?

rigor789 commented 1 year ago

The issue itself is mostly a "can't fix" because it's a platform enforced limitation, as for helpers - I can't say for sure, but that would belong to a feature request with some details what the helper would do/look like. Feel free to open one to discuss that part of it further!

KIC commented 4 months ago

the app is showing the setting but the switch is disabled so you can't do anything. how are we supposed to migrate files? maybe at least add a GitHub integration to save and get back files.