Closed keshav-space closed 2 years ago
read
media and files but can't modify or create files except in app-specific storage space
[ moreover, the android will never expose the actual file location rather a cached file location is shared with apps]MANAGE_EXTERNAL_STORAGE
permission is granted, app can read/modify/create/delete
files in external shared storage.These access control will become more stringent in the coming year, something similar to iOS, and that's good for user privacy. Bottom line is that apps should not use All file Permission
unless absolutely needed.
Safe Notes will not use All File Permission
, this means that users will not be able to choose the location of their choice for backup. Backup will be made inside the Download directory within the Safe Notes folder. [See videos below ]
Android 12 | Android 12 | Android 11 | Android 10 |
---|---|---|---|
Android 9 | Android 8.1 | Android 8.0 | Android 7.1 |
Thanks for the reply, I understand.
I just would like to ask why Safe Notes doesn't use this method used by most modern apps to gain access to a specific directory.
I just would like to ask why Safe Notes doesn't use this method used by most modern apps to gain access to a specific directory.
Safe Notes is already using this for reading import files [ user can pick the import file from anywhere while importing backup]
This permission can't be used to write/modify existing files moreover the new files can only be created in the Download directory or app-specific storage location.
To write a file at an arbitrary [user chosen] location app would require MANAGE_EXTERNAL_STORAGE
permission
There is no escape from this.
I am very sorry, I linked the wrong thing. This intent FLAG_GRANT_WRITE_URI_PERMISSION
should be the right one (if it's not, I really have to apologize for annoying you without having any idea myself).
You may want to have a look at this notes app:
autoExportLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
val uri = result.data?.data
if (result.resultCode == Activity.RESULT_OK && uri != null) {
val output = try {
val cr = context.contentResolver
cr.takePersistableUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
cr.openOutputStream(uri)
} catch (e: Exception) {
Log.i(TAG, "Data export failed", e)
null
}
if (output != null) {
viewModel.setupAutoExport(output, uri.toString())
} else {
showMessage(R.string.export_fail)
autoExportPref.isChecked = false
}
}
}
fun setupAutoExport(output: OutputStream, uri: String) {
prefsManager.autoExportUri = uri
viewModelScope.launch(Dispatchers.IO) {
val jsonData = jsonManager.exportJsonData()
try {
output.use {
output.write(jsonData.toByteArray())
}
showMessage(R.string.export_success)
val now = System.currentTimeMillis()
prefsManager.lastAutoExportTime = now
_lastAutoExport.postValue(now)
} catch (e: Exception) {
showMessage(R.string.export_fail)
}
}
}
Here is a screen recording:
This intent
FLAG_GRANT_WRITE_URI_PERMISSION
should be the right one.
I see you're pointing to the Storage Access Framework
and I could have used that, but the only problem I'm having is that the SAF gives you a content URI that doesn't reflect the exact location of the file on the filesystem.
Suppose user creates a backup file at a certain location, the app will receive the content URI of that file. The app can access and modify the content of that file using content URI, but the app has no clue about where the file is exactly stored, so the app can't show the location of the backup file inside the app. And this is a problem because, a few months down the line, user will forget where they created the backup file. (happens to me all the time, lol 😆) Since the app can't show the exact location of the file, user will end up creating a new backup and this will go on.
For an offline app, it's paramount that the user can independently access the backup file.
if it's not, I really have to apologize for annoying you without having any idea myself
Indulgence is much appreciated and always welcome, that's the point of having this open-source. 😊
SAF would work only if there was some way to show the exact location of backup file like this 👇
Hello again. This app (https://github.com/T8RIN/ImageToolbox) allows to pick a location and it is also able to show it. If there still is interest in working on this app, it may be worth a look.
https://github.com/keshav-space/safenotes/assets/115401023/4997811b-eeec-4791-a2e5-ed84ce62307c
I still can't on 2.1.0