Android 6.0 向后兼容

Android 6.0 backward compatibility

今天我在 Android M (6.0) 上测试我的一个应用程序。我了解此版本中的权限授予已更改,我需要进行一些更改以使我的应用程序与 Android 6.0 (here is the details).

兼容

据我了解,例如,如果我想授予写入 sdcard(永久存储)的权限,这是一个危险的权限,我必须要求用户授予访问权限,然后处理用户决定(grant/deny ) 否则我的请求总是被拒绝。

我不知道我说的对不对,但我想知道它是否以某种方式违反了向后兼容性?我的意思是每个在旧版本中为 运行 的应用程序都需要更改为在 6.0 版中获得 运行 吗?如果不再支持特殊应用,那么android6.0是我们该告别的地方了?

在这种新环境下,我需要更改我的旧应用程序以在 Marshmallow 中制作它们 运行(如果它们需要危险权限)?

似乎保持了向后兼容性。来自 the page you linked

  • If the device is running Android 5.1 or lower, or your app's target SDK is 22 or lower: If you list a dangerous permission in your manifest, the user has to grant the permission when they install the app; if they do not grant the permission, the system does not install the app at all.
  • If the device is running Android 6.0 or higher, and your app's target SDK is 23 or higher: The app has to list the permissions in the manifest, and it must request each dangerous permission it needs while the app is running. The user can grant or deny each permission, and the app can continue to run with limited capabilities even if the user denies a permission request.

因此,旧版应用(针对 SDK 22 或更低版本)将看到安装时授予权限的旧行为。只有针对 SDK 23 或更高版本的新应用才需要立即担心这一点。

该页面确实列出了一个您应该注意的警告:

Note: Beginning with Android 6.0 (API level 23), users can revoke permissions from any app at any time, even if the app targets a lower API level. You should test your app to verify that it behaves properly when it's missing a needed permission, regardless of what API level your app targets.

这对您的应用(甚至是旧应用)意味着它们需要能够在失去您通常期望它们拥有的特权的情况下生存下来。相应地测试和更新。

这对于您安装的任何第三方遗留应用程序意味着,在撤销其权限时必须谨慎行事,因为假定其特权操作将成功的应用程序可能会在这些权限被意外撤销时出现问题。显然,第三方开发人员应该对此进行测试和解决,但这可能并不总是发生。

来自 Android 文档:

On all versions of Android, your app needs to declare both the normal and the dangerous permissions it needs in its app manifest, as described in Declaring Permissions. However, the effect of that declaration is different depending on the system version and your app's target SDK level:

  • If the device is running Android 5.1 or lower, or your app's target SDK is 22 or lower: If you list a dangerous permission in your manifest, the user has to grant the permission when they install the app; if they do not grant the permission, the system does not install the app at all.
  • If the device is running Android 6.0 or higher, and your app's target SDK is 23 or higher: The app has to list the permissions in the manifest, and it must request each dangerous permission it needs while the app is running. The user can grant or deny each permission, and the app can continue to run with limited capabilities even if the user denies a permission request.

如果您想在 Android 6.0 中 运行 您的应用程序,那么您必须在 运行 时编写请求权限的逻辑。
但它不会改变您的应用程序在旧版本中的行为,对于这些情况,将在安装时请求权限。