原文:https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-runtime-permissions
除了功能和性能,Android 6.0 (API level 23)包括一系列系统变化和API行为变化。这个文档重点介绍其中需要你理解和为你的APP负责的一些关键点。
如果你以前发布过Android APP,要知道这些问题会不会影响你的APP。

一、关键点:

1、运行时权限:Runtime Permissions
2、睡眠和APP待机模式:Doze and App Standby
3、移除Apache HTTP:Apache HTTP Client Removal
3、BoringSSL
4、访问硬件标识:Access to Hardware Identifiers
5、通知:Notifications
6、音频管理:AudioManager Changes
7、文字选择:Text Selection
8、浏览器书签:Browser Bookmark Changes
9、APP签名:Android Keystore Changes
10、WIFI和网络:Wi-Fi and Networking Changes
11、相机服务:Camera Service Changes
12、运行时:Runtime
14、APK校验:APK Validation
15、USB连接:USB Connection
16、Android企业版变化:Android for Work Changes

二、详解:

1、Runtime Permissions:

This release introduces a new permissions model, where users can now directly manage app permissions at runtime. This model gives users improved visibility and control over permissions, while streamlining the installation and auto-update processes for app developers. Users can grant or revoke permissions individually for installed apps.
这个发布版本引入了新的权限模式,可以让用户直接管理APP的运行时权限。这种模式给用户提升了可见性和权限控制。同时简化了APP开发人员的安装和自动升级过程。用户可以单独给每个安装的APP授权或取消授权。

On your apps that target Android 6.0 (API level 23) or higher, make sure to check for and request permissions at runtime. To determine if your app has been granted a permission, call the new checkSelfPermission() method. To request a permission, call the new requestPermissions() method. Even if your app is not targeting Android 6.0 (API level 23), you should test your app under the new permissions model.
在你API6.0或更高版本的APP中,确保在运行时检查和请求权限。为了确定你的APP是否被授权,你可以调用的新的方法:checkSelfPermission()。如果要请求权限,你可以调用新增方法requestPermissions()。即使你的APP使用API不是23,你也应该在新的权限模式下测试。

For details on supporting the new permissions model in your app, see Working with System Permissions. For tips on how to assess the impact on your app, see Permissions Best Practices.
想了解新权限模式对你APP的更多支持,查看Working with System Permissions。关于怎么样评估对你APP的影响的一些建议,查看Permissions Best Practices

2、Doze and App Standby:

This release introduces new power-saving optimizations for idle devices and apps. These features affect all apps so make sure to test your apps in these new modes.
这个发布版本引入了设备和APP省电的新策略。这些功能会影响所有的APP,所以你得确保在新的模式下测试你的APP。

Doze: If a user unplugs a device and leaves it stationary, with its screen off, for a period of time, the device goes into Doze mode, where it attempts to keep the system in a sleep state. In this mode, devices periodically resume normal operations for brief periods of time so that app syncing can occur and the system can perform any pending operations.
打盹:如果用户拔掉电源并关掉屏幕,把设备放置在那里,过一段时间,设备会进入Doze模式,Doze模式会使系统进入休眠状态。这种模式下,设备会周期性的恢复正常一些短暂的操作,使得APP的同步会发生,同样的,系统也会执行一些挂起的操作。

App Standby: App Standby allows the system to determine that an app is idle when the user is not actively using it. The system makes this determination when the user does not touch the app for a certain period of time. If the device is unplugged, the system disables network access and suspends syncs and jobs for the apps it deems idle.
APP待命:APP等待模式运行系统确定一个APP是用户没有使用它的空闲状态。系统是通过检测一个特定的时间段内用户没有触摸APP来确定的。如果设备没有接通电源,系统会断开网络接入,暂停同步,APP的任务会被认为是空闲的。

To learn more about these power-saving changes, see Optimizing for Doze and App Standby.
想了解更多关于省电的改变,查看:Optimizing for Doze and App Standby

3、Apache HTTP Client Removal

Android 6.0 release removes support for the Apache HTTP client. If your app is using this client and targets Android 2.3 (API level 9) or higher, use theHttpURLConnectionclass instead. This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption. To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in yourbuild.gradlefile:

android {            useLibrary 'org.apache.http.legacy'}

Android 6.0发布版移除了对Apache HTTP client的支持。如果你的APP使用了它并且target>=9,请用HttpURLConnection代替。这个接口会更高效,因为通过压缩传输和响应缓冲简述了网络的使用,同时减少电量的消耗。想继续使用Apache HTTP APIs,你必须在你的.gradle文件中配置编译依赖。

4、BoringSSL

Android is moving away from OpenSSL to the BoringSSL library. If you’re using the Android NDK in your app, don't link against cryptographic libraries that are not a part of the NDK API, such as libcrypto.so
and libssl.so. These libraries are not public APIs, and may change or break without notice across releases and devices. In addition, you may expose yourself to security vulnerabilities. Instead, modify your native code to call the Java cryptography APIs via JNI or to statically link against a cryptography library of your choice.
Android已经从库从OpenSSL移到了BoringSSL。如果你的APP使用了Android NDK,不用依赖cryptographic库,它已经不是NDK API的一部分了,比如:libcrypto.so和libssl.so。这些库已经不是公开的API了,很多改变都不会通知发布版和设备了。另外你可能会暴露你APP的安全弱点。相反,你应该修改你的本地代码通过JNI调用Java层的加密API,或者连接一些你选择的静态库。

5、Access to Hardware Identifier

To provide users with greater data protection, starting in this release, Android removes programmatic access to the device’s local hardware identifier for apps using the Wi-Fi and Bluetooth APIs. The WifiInfo.getMacAddress()
and the BluetoothAdapter.getAddress()
methods now return a constant value of 02:00:00:00:00:00
.
To access the hardware identifiers of nearby external devices via Bluetooth and Wi-Fi scans, your app must now have the ACCESS_FINE_LOCATION
orACCESS_COARSE_LOCATION
permissions:
WifiManager.getScanResults()
BluetoothDevice.ACTION_FOUND
BluetoothLeScanner.startScan()

Note: When a device running Android 6.0 (API level 23) initiates a background Wi-Fi or Bluetooth scan, the operation is visible to external devices as originating from a randomized MAC address.

为了给用户提供更大的数据保护,从这个发布版开始,Android移除了APP使用WiFi和蓝牙接入硬件标识的接口。 WifiInfo.getMacAddress()
和BluetoothAdapter.getAddress()方法现在返回02:00:00:00:00:00.
现在想访问硬件标识,如:WiFi和蓝牙,必须要有 ACCESS_FINE_LOCATION
或者ACCESS_COARSE_LOCATION权限:
WifiManager.getScanResults()
BluetoothDevice.ACTION_FOUND
BluetoothLeScanner.startScan()
注意: 当一个设备运行Android 6.0初始化一个后台的WiFi或蓝牙扫描时,这个操作对其他外部设备来说是一个随机的可见地址。

6、Notifications

This release removes the Notification.setLatestEventInfo()
method. Use the Notification.Builder class instead to construct notifications. To update a notification repeatedly, reuse the Notification.Builder instance. Call the build() method to get updated Notification instances.
The adb shell dumpsys notification command no longer prints out your notification text. Use the adb shell dumpsys notification --noredact command instead to print out the text in a notification object.

这个发布版移除了Notification.setLatestEventInfo()方法。使用Notification.Builder 代替构建通知。再次使用Notification.Builder 来更新通知。调用 build() 得到更新后的通知实例。使用adb shell dumpsys notification命令不再打印通知的文本。用adb shell dumpsys notification --noredact 命令代替打印通信对象。

7、AudioManager Changes

Setting the volume directly or muting specific streams via the AudioManager class is no longer supported. The [setStreamSolo()](https://developer.android.com/reference/android/media/AudioManager.html#setStreamSolo(int, boolean)) method is deprecated, and you should call the [requestAudioFocus()](https://developer.android.com/reference/android/media/AudioManager.html#requestAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener, int, int)) method instead. Similarly, the [setStreamMute()](https://developer.android.com/reference/android/media/AudioManager.html#setStreamMute(int, boolean)) method is deprecated; instead, call the[adjustStreamVolume()](https://developer.android.com/reference/android/media/AudioManager.html#adjustStreamVolume(int, int, int)) method and pass in the direction value ADJUST_MUTE or ADJUST_UNMUTE

通过使用 AudioManager 来直接设置音量或静音已经不再支持了。[setStreamSolo()](https://developer.android.com/reference/android/media/AudioManager.html#setStreamSolo(int, boolean)) 方法已经被遗弃了,你应该调用 [requestAudioFocus()](https://developer.android.com/reference/android/media/AudioManager.html#requestAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener, int, int))方法。同样的setStreamMute()方法也被遗弃了,应该调用adjustStreamVolume() 方法,直接传 ADJUST_MUTE 和 ADJUST_UNMUTE。

8、Text Selection

When users select text in your app, you can now display text selection actions such asCut, Copy, and Paste in a floating toolbar. The user interaction implementation is similar to that for the contextual action bar, as described in Enabling the contextual action mode for individual views.
To implement a floating toolbar for text selection, make the following changes in your existing apps:
In your View
or Activity
object, change your ActionMode
calls fromstartActionMode(Callback)
to startActionMode(Callback, ActionMode.TYPE_FLOATING)
.
Take your existing implementation of ActionMode.Callback
and make it extendActionMode.Callback2
instead.
Override the [onGetContentRect()](https://developer.android.com/reference/android/view/ActionMode.Callback2.html#onGetContentRect(android.view.ActionMode, android.view.View, android.graphics.Rect))
method to provide the coordinates of the contentRect
object (such as a text selection rectangle) in the view.
If the rectangle positioning is no longer valid, and this is the only element to be invalidated, call the invalidateContentRect()
method.

If you are using Android Support Library revision 22.2, be aware that floating toolbars are not backward-compatible and appcompat takes control over ActionMode
objects by default. This prevents floating toolbars from being displayed. To enable ActionMode
support in an AppCompatActivity
, call getDelegate()
, then callsetHandleNativeActionModesEnabled()
on the returned AppCompatDelegate
object and set the input parameter to false
. This call returns control of ActionMode
objects to the framework. In devices running Android 6.0 (API level 23), that allows the framework to support ActionBar
or floating toolbar modes, while on devices running Android 5.1 (API level 22) or lower, only the ActionBar
modes are supported.

更多相关文章

  1. android自定义Adapter
  2. android Permission 访问权限许可 大全
  3. Android获取View的宽高与View.measure详解
  4. Android(安卓)Camera 二 JNI JAVA和C/CPP图像数据传输流程分析
  5. Android(安卓)官方架构组件(一)——Lifecycle
  6. Android基于Http协议实现文件上传功能的方法
  7. 倒计时效果
  8. SDK is not loaded yet解决方法
  9. 【Android】原生Progress提示

随机推荐

  1. sqlite数据库默认自增标号RecNo与integer
  2. 安卓Android大量项目源码实例
  3. 在4.0以上系统中应用出现2.3版本的系统UI
  4. 2013.07.11——— android MediaRecorder
  5. Android编码规范
  6. 【翻译】(8-补丁1)Android接口定义语言(AI
  7. Android之Google Map(一)
  8. android 多项对话框
  9. android有用网址
  10. [转] 软键盘android:windowSoftInputMode