英文:
Is it possible to access a document created using the intent with its path?
问题
在升级到API 33时,从API 28,我无法再访问使用ACTION_CREATE_DOCUMENT意图创建的文件,除非使用其URI。
我已经尝试确保在尝试访问文件之前获取了READ_EXTERNAL_STORAGE和WRITE_EXTERNAL_STORAGE权限。我成功创建了文件,但当创建其路径并尝试在该路径上访问它时,应用程序突然无法打开它,即使它应该是该文件的所有者,如果我没记错的话?
我绝对不能使用MANAGE_EXTERNAL_STORAGE权限,因为这不适用于我的用例。
是否有一种方法可以使用路径而不是返回的URI来写入文件?文件扩展名是csv。
英文:
While working to upgrade to API 33 from API 28 I can no longer access the files that I have created with ACTION_CREATE_DOCUMENT intent without using its URI.
I have tried making sure to ensure READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions were taken before attempting to access the file. I manage to create the file but when creating its path and trying to access it at that path the app suddenly fails to open it even though it should be the owner of that file if I'm not wrong?
I absolutely cannot use MANAGE_EXTERNAL_STORAGE permission because that doesn't fit the usecase that I have.
Is there a way to use the path instead of the URI returned to write to the file? the file extension is csv.
答案1
得分: 0
I have created a sample to write and read the file.
Create the File:
Intent intent = new Intent(Intent.ActionCreateDocument);
intent.AddCategory(Intent.CategoryOpenable);
intent.SetType("application/txt");
intent.PutExtra(Intent.ExtraTitle, "anew.txt");
StartActivity(intent);
Then I saved the file into the Download Folder by the system file manager and write the file.
File.WriteAllText("/storage/emulated/0/Download/anew.txt", "this is file content");
Every thing worked well after I granted the storage permission to my app. But when I saved the file in the Documents Folder, I will get the error about accessing path /storage/emulated/0/Documents/anew.txt is denied.
The read and write storage permission can't access the Documents Folder with a path.
英文:
I have created a sample to write and read the file.
Create the File:
Intent intent = new Intent(Intent.ActionCreateDocument);
intent.AddCategory(Intent.CategoryOpenable);
intent.SetType("application/txt");
intent.PutExtra(Intent.ExtraTitle, "anew.txt");
StartActivity(intent);
Then I saved the file into the Download Folder by the system file manager and write the file.
File.WriteAllText("/storage/emulated/0/Download/anew.txt", "this is file content");
Every thing worked well after I granted the storage permission to my app. But when I saved the file in the Documents Folder, I will get the error about accessing path /storage/emulated/0/Documents/anew.txt is denied.
The read and write storage permission cann't access the Documentss Folder with a path.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论