关于 android:installLocation 权限的困惑

Confusion about android:installLocation permissions

只是查看我的应用程序的权限,我想知道在使用 android:installLocation="auto".

时我的清单中是否需要 android.permission.READ_EXTERNAL_STORAGE

我查看了 developer docs which do not mention anything about permissions, but other documentation 声明我确实需要从外部存储读取的权限:

In order to read or write files on the external storage, your app must acquire the READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE system permissions.

此外,documentation about the permission 指出:

Allows an application to read from external storage.

Any app that declares the WRITE_EXTERNAL_STORAGE permission is implicitly granted this permission.

This permission is enforced starting in API level 19. Before API level 19, this permission is not enforced and all apps still have access to read from external storage. You can test your app with the permission enforced by enabling Protect USB storage under Developer options in the Settings app on a device running Android 4.1 or higher.

Also starting in API level 19, this permission is not required to read/write files in your application-specific directories returned by getExternalFilesDir(String) and getExternalCacheDir().

因此我不确定我是否需要清单文件中 installLocation 属性的权限,因为这意味着我的应用程序将从外部存储读取,但正如我之前所说,文档具体在 App Install Location 上没有提到权限。

我需要权限吗?

您不需要权限。

在 Android 6.0 之前,android:installLocation 不会影响您应用的内部存储(例如,getFilesDir())。它只会影响您的 APK 所在的位置。因此,权限不适用。

Android 6.0 现在允许用户将可移动存储(例如微型 SD 卡)用作安装应用程序的专用位置。在这种情况下,您的内部存储恰好位于可移动存储上的加密分区上。但是,这仍然不是外部存储,因此权限不适用。