在sdcard android 4.4及更高版本的私有目录上写入应用程序数据 [英] Write application data on private directory on sdcard android 4.4 and above

查看:122
本文介绍了在sdcard android 4.4及更高版本的私有目录上写入应用程序数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于此主题的问题很多,但我的纠正示例找不到任何答案.

There are many questions about this topic, but I cannot find any answers for my corrective example.

我正在使用Samsung galaxy S5运行android 4.4,这仅限于存储

I'm using Samsung galaxy S5 run android 4.4, which is limited for storage

官方文件说:

WRITE_EXTERNAL_STORAGE权限只能授予对设备上主要外部存储的写访问权限.除合成权限允许的应用程序特定于程序包的目录外,不得允许应用程序写入辅助外部存储设备.以这种方式限制写操作可确保系统在卸载应用程序时可以清理文件.

The WRITE_EXTERNAL_STORAGE permission must only grant write access to the primary external storage on a device. Apps must not be allowed to write to secondary external storage devices, except in their package-specific directories as allowed by synthesized permissions. Restricting writes in this way ensures the system can clean up files when applications are uninstalled.

我的应用程序需要将文件写入Sdcard(绝对路径为/storage/extSdCard ),因此我将应用程序数据写入我的应用程序目录:/storage/extSdCard/Android/com.myapp.example/files ,但权限被拒绝.所以我怀疑上面的说法:

My application need to write files to Sdcard (Absolute path is /storage/extSdCard), so I write my app data to my app directory: /storage/extSdCard/Android/com.myapp.example/files but got permission denied exception. So I suspect the above statement:

,但在综合允许的特定于软件包的目录中除外权限

except in their package-specific directories as allowed by synthesized permissions

我认为我无法写入根目录/storage/extSdCard ,但仍然能够将我的应用程序数据写入我的应用程序包目录.我在这里误会了吗?

I think I cannot write to root directory /storage/extSdCard but still able to write my app data to my app package directory. Did I misunderstand something here?

p/s:我仍然可以将我的应用程序数据写入内置存储:/storage/emulated/0/Android/data/com.myapp.example/files .我不想使用 getExternalFileDirs(),因为它总是返回内置的,而不是我的sdcard目录.

p/s: I still able to write my app data to built-in storage: /storage/emulated/0/Android/data/com.myapp.example/files. I don't want to use getExternalFileDirs() because it always return built-in, not my sdcard directory.

推荐答案

如果getExternalFilesDir(null)返回的位置不同于/storage/extSdCard/Android/com.myapp.example/files,那么我认为这就是原因给您访问权限错误.您可以在没有权限的情况下写入SD卡的唯一位置是getExternalFilesDir()返回的目录

If getExternalFilesDir(null) is returning somewhere different to /storage/extSdCard/Android/com.myapp.example/files, then I would think that is why it is giving you access permission errors. The only place on the SD card you can write to without permissions is the directory returned by getExternalFilesDir()

由于您说由getExternalFilesDir(null)返回的目录是不可接受的,所以我建议向清单中添加WRITE_EXTERNAL_STORAGE权限.

Since you say the directory returned by getExternalFilesDir(null) is not acceptable, I would suggest adding the WRITE_EXTERNAL_STORAGE permission to your manifest.

这篇关于在sdcard android 4.4及更高版本的私有目录上写入应用程序数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆