Permission of app specific folder on external storage

南楼画角 提交于 2019-12-02 04:52:46
Vaiden

Let's talk some Android security, shall we?

  1. You can not access an application's home directory, on an unrooted device. This would have been a MAJOR security hole.

  2. Creating WORLD_READABLE files is deprecated, and judging by the text in the API, this is one of those cases where "decperacted" means "deprecated".

  3. So - you wanna pass data between applications?

    a. You can leave a file in a set place for the 2nd app to fetch. This is a bad idea though. It litters the user's storage space, there is NO SECURITY at all, the 2nd app is not notified about pending updates and you can not easily determine the state of affairs. I suggest you stear away from this approach. Even though, I've included some elaboration in the UPDATE section below.

    b. For simple, small chunks of data, I suggest you go the Intent/BroadcastReceiver approach.

    c. You can go the ContentProvider approach is you wanna do things the right way.

    d. You can go the Intent/Service approach.

    e. For true IPC - use AIDL.

UPDATE:

I suggest you begin by reading Google's article throughly. This article clearly deals with the case of transfering large files between apps. Also, as you can clearly witness, the terminology is quite confusing.

So let's review your question in light of Google's article on the subject.

Internal storage is private to your application and can not be accessed by other apps. You can access its directory structure via Context.html#getFilesDir().

Please mind that:

  1. Files written here are deleted when the user uninstalls the app.

External storage can be physically internal (built in storage) or external (removable SD card). There is no security model here, files are visible and accessible to the world. You can access the external directory structure via Context.html#getExternalFilesDir(). Please mind that:

  1. This direcory might become unaccessible (when the user connects the device to a computer or when he removes the SD card).

  2. There might be a seperate directory per device user.

  3. Files remain even when the user uninstalls the app.

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

Indra's point is correct. for reading EXTERNAL_STORAGE you need to put this uses-permission

try this permission

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Richard Le Mesurier

As far as I knew, the files on the external storage are public, but as Indra points out you do need the permission if you want your app to read them:

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

I think it is only the internal storage files that are private, requiring ROOT access to be read from outside your app (or an app signed with the same key as your app).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!