Android 6.0 新特性(官方文档翻译)

转自http://blog.csdn.net/u013174702/article/details/50835891
Android 6.0 的变化(Android 6.0 Changes)

随着新的特性和功能,Android 6.0 (API level 23), 系统和API的行为发生了很多改变。本文强调一些关键的变化,你应该在你的程序中考虑和理解。
如果你有以前发布的Android应用程序,请注意,这些变化在这个版本上会对你的应用程序有影响。

运行时权限(Runtime Permissions)

这个版本引入了一个新的权限模型,就是用户可以直接管理应用权限在app运行的时候。这个模型给用户提高了权限的可见和控制,同时对于开发者又简化了安装和升级过程。用户可以对某个程序授予或撤回某个权限。

如果你的应用建立在Android 6.0或者更高,请确保你的应用是在运行时检查和请求权限。确定你的应用被授予权限,调用新的checkSelfPermission()方法,请求权限调用新的requestPermissions()方法。甚至你的app不是建立在Android 6.0上的,你也应该尝试用这种新的权限模型。

想了解更多的细节对于app支持新的权限模型请看 Working with System Permissions。想了解对你程序影响有多大请看Permissions Best Practices.
Doze 和 App Standby模式(Doze and App Standby)

这个特性引入了新的节能模式,当你的设备或者app进入闲置状态,例如屏幕关闭。这个模式会影响你所有的app,所以确保你的app在这个模式下测试过。

Doze:当用户设备没有连接电源并且没有什么活动,屏幕关闭(也就是你没用手机的时候),在这段时间,你的设备会进入Doze模式,它会尝试让你的系统保持在睡眠状态。在这个模式下,系统定期提供一个短暂的时间让应用程序完成延迟的工作活动,在这个时间片里,系统将提供维持性窗口应用程序访问网络,运行在等待的同步,工作,和报警等活动。

App Standby: App Standby 允许系统决定app空闲,当用户没有一直使用这个app的时候。如果在一定时间内用户没有点击这个应用,系统就会做出这个决定。在设备没有充电的时候,一旦系统认定某个应用处于空闲状态,那么系统将会禁用这个应用的网络访问和暂停同步。

想了解更多关于节能的改变,请看Optimizing for Doze and App Standby.
移除Apache HTTP Client(Apache HTTP Client Removal)

Android 6.0版本移除了对Apache HTTP Client的支持。如果你的app建立在Android 2.3 (API level 9) 或更高,使用HttpURLConnection类替代。这个api有更高的效率,它减少网络的使用通过透明压缩和响应缓存(译者并不知道这是什么意思),并且将能耗降到最低。如果想继续使用Apache HTTP APIs,你必须在你的build.gradle的dependency 下先声明

android {
useLibrary ‘org.apache.http.legacy’
}
BoringSSL(BoringSSL)

Android不用OpenSSL,开始使用BoringSSL。如果你在你的app中使用了NDK,don’t link against cryptographic libraries that are not a part of the NDK API, such as libcrypto.so and libssl.so. (没接触过NDK开发,实在不懂这是什么意思)。这些库不是公共的api,在跨版本或设备的时候可能会发生改变并且没有通知。另外,你可能会暴露自己的安全漏洞。相反,你可以通过调用java加密api(调用JNI或者statically link against a cryptography library)来修改你本地的代码。
访问硬件标识符(Access to Hardware Identifier)

从这个版本开始,我们给用户提供了更好的数据保护,在WiFi和Bluetooth API中,移除了对本地硬件标识符的访问,WifiInfo.getMacAddress()和BluetoothAdapter.getAddress()方法只会返回一个常量02:00:00:00:00:00。
如果你想通过WiFi和Bluetooth扫描来访问附近的外部设备,你的app必须有ACCESS_FINE_LOCATION 或者 ACCESS_COARSE_LOCATION权限。

WifiManager.getScanResults()
BluetoothDevice.ACTION_FOUND
BluetoothLeScanner.startScan()
note:当设备运行 Android 6.0 (API level 23) 启动后台 Wi-Fi 或蓝牙扫描时,the operation is visible to external devices as originating from a randomized MAC address.(这个意思好像是说扫描到的这个外部设备的mac地址是随机的,原谅译者英语太差。。)
通知(Notifications)

这个版本移除了Notification.setLatestEventInfo()方法。使用Notification.Builder类来创建通知。若要多次更新通知,重用Notification.Builder实例。调用build()方法来获取更新的notification实例。
adb shell dumpsys notification指令不会再输出notification文本,而是使用adb shell dumpsys notification –noredact指令替代。
AudioManager改变(AudioManager Changes)

AudioManager类不再支持直接设置音量或静音特定的流程。SetStreamSolo()方法已被弃用,你应该调用requestAudioFocus()方法替代。同样的,setStreamMute()方法也被弃用,相反,调用adjustStreamVolume()方法并传ADJUST_MUTE或 ADJUST_UNMUTE。
文本选择(Text Selection)

当用户在你的app中选择了文本,你现在就可以通过floating bar展示一些文本操作选项,例如复制、粘贴、剪切。这种交互的实现类似于上下文的操作栏。图片标题

为了实现这个floating bar,你需要在你的app中做出如下改变

1、在你的view或者activity中,改变你ActionMode调用,把startActionMode(Callback)换成startActionMode(Callback, ActionMode.TYPE_FLOATING).
2、找到你原来ActionMode.Callback的实现,把它换成继承 ActionMode.Callback2。
3、重写onGetContentRect()方法,给Rect对象提供view中的坐标(例如文本选择的方框)。
4、如果矩形的位置不再有效,and this is the only element to be invalidated(大概是只是矩形的位置无效了的话),调用invalidateContentRect()方法。
如果你正在使用 Android Support Library22.2,请注意,floating bar并不是向后兼容,并且appcompat 默认采用 ActionMode 对象的控制权。这会阻止floating bar的显示。为了使ActionMode支持AppCompatActivity,调用getDelegate(),然后在返回的AppCompatDelegate对象上调用 setHandleNativeActionModesEnabled() 并将输入的参数设置为 false。此调用返回 ActionMode 对象的控制。在Android 6.0 (API level 23),允许framework支持actionBar和 floating toolbar模式,而在 Android 5.1 (API level 22)或更低,则只支持actionBar模式。
浏览器书签变化(Browser Bookmark Changes)

这个版本移除了对全局书签(global bookmarks,这是个什么鬼)的支持。android.provider.Browser.getAllBookmarks()和android.provider.Browser.saveBookmark()这两个方法也移除了。同样的,READ_HISTORY_BOOKMARKS和WRITE_HISTORY_BOOKMARKS权限也没有了。所以如果你的app是建立在Android 6.0 (API level 23)及以上,就不要再用了,你应该把书签数据保存在本地。
Android KeyStore 变化(Android Keystore Changes)

在这个版本中,Android Keystore provider不再支持DSA。ECDSA 仍然被支持。Keys which do not require encryption at rest will no longer be deleted when secure lock screen is disabled or reset (for example, by the user or a Device Administrator). Keys which require encryption at rest will be deleted during these events.(看不懂了)。
Wi-Fi 和 Networking 改变(Wi-Fi and Networking Changes)

这个版本在Wi-Fi 和 Networking API中又做了如下改变:

你的app现在可以改变WifiConfiguration对象的状态,只要你创建了这些对象。你不在允许修改或删除由用户或者其他app创建的WifiConfiguration对象。
以前,如果你的app强制设备连接某一个特定的wifi网络通过enableNetwork()并且disableAllOthers=true,那你的设备将会从其他网络断开,例如蜂窝数据。在这个版本中,你的设备将不会再从其他网络断开。如果你的targetSdkVersion在20或者更低,他将被固定到选定的WiFi网络。如果你的 targetSdkVersion在21或更高, use the multinetwork APIs (such as openConnection(), bindSocket(), and the new bindProcessToNetwork() method) to ensure that its network traffic is sent on the selected network.(不懂)
相机服务改变(Camera Service Changes)

在这个版本中,访问共享资源的模型已经从先来先服务变成先服务优先级高的。服务行为的变化包括:

对相机子系统资源的访问,包括打开并配置相机设备,都会根据客户端应用进程授予优先级,一般来说用户可见或者在前面的activity的进程优先级更高,使相机资源的获取和使用更可靠。
当优先级高的程序和优先级低的程序同时使用相机资源的时候,优先级低的可能会被驱逐(也就是无法使用相机资源)。在已经弃用的Camera API中,客户端被驱逐时会调用OnError()。在Camera2中,客户端被驱逐会调用onDisconnected()。
当你的设备相机正常,单独的应用程序进程能够独立开放和同时使用独立的相机设备。然而在多进程使用的情况下,当同时打开相机设备会造成严重的性能下降,现在的Camera Service已经不允许这种情况并删除。这可能会造成你的app被”驱逐“,甚至没有其他应用想要使用相机的时候也可能发生。
Changing the current user causes active camera clients in apps owned by the previous user account to be evicted. Access to the camera is limited to user profiles owned by the current device user. In practice, this means that a “Guest” account, for example, will not be able to leave running processes that use the camera subsystem when the user has switched to a different account.(好像是和用户账户有关的东西,不太懂)
运行时间(Runtime)

有心人给翻译一下吧
The ART runtime now properly implements access rules for the newInstance() method. This change fixes a problem where Dalvik was checking access rules incorrectly in previous versions. If your app uses the newInstance() method and you want to override access checks, call the setAccessible() method with the input parameter set to true. If your app uses the v7 appcompat library or the v7 recyclerview library, you must update your app to use to the latest versions of these libraries. Otherwise, make sure that any custom classes referenced from XML are updated so that their class constructors are accessible.

This release updates the behavior of the dynamic linker. The dynamic linker now understands the difference between a library’s soname and its path ( public bug 6670), and search by soname is now implemented. Apps which previously worked that have bad DT_NEEDED entries (usually absolute paths on the build machine’s file system) may fail when loaded.

The dlopen(3) RTLD_LOCAL flag is now correctly implemented. Note that RTLD_LOCAL is the default, so calls to dlopen(3) that didn’t explicitly use RTLD_LOCAL will be affected (unless your app explicitly used RTLD_GLOBAL). With RTLD_LOCAL, symbols will not be made available to libraries loaded by later calls to dlopen(3) (as opposed to being referenced by DT_NEEDED entries).

On previous versions of Android, if your app requested the system to load a shared library with text relocations, the system displayed a warning but still allowed the library to be loaded. Beginning in this release, the system rejects this library if your app’s target SDK version is 23 or higher. To help you detect if a library failed to load, your app should log the dlopen(3) failure, and include the problem description text that the dlerror(3) call returns. To learn more about handling text relocations, see this guide.
APK验证(APK Validation)

现在的平台对于apk有更严格的验证。 An APK is considered corrupt if a file is declared in the manifest but not present in the APK itself. An APK must be re-signed if any of the contents are removed.(编不下去了)
USB连接(USB Connection)

现在设备连接到usb的时候默认的额模式是仅充电。为了通过USB连接进入到设备获取内容。用户必须授予一些权限为了交互。如果你的app支持通过usb让用户和设备交互,你要考虑交互必须是显示启用。
安卓工作的改变(Android for Work Changes)

在这个版本中,以下安卓工作行为发生改变:

Work contacts in personal contexts. The Google Dialer Call Log now displays work contacts when the user views past calls. Setting setCrossProfileCallerIdDisabled() to true hides the work profile contacts in the Google Dialer Call Log. Work contacts can be displayed along with personal contacts to devices over Bluetooth only if you set setBluetoothContactSharingDisabled() to false. By default, it is set to true.
**无线网络配置删除:**Wi-Fi configurations added by a Profile Owner (for example, through calls to the addNetwork() method) are now removed if that work profile is deleted.
Wi-Fi configuration lockdown: Any Wi-Fi configuration created by an active Device Owner can no longer be modified or deleted by the user if WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN is non-zero. The user can still create and modify their own Wi-Fi configurations. Active Device Owners have the privilege of editing or removing any Wi-Fi configurations, including those not created by them.
**Download device policy controller via Google account addition:**When a Google account that requires management via a device policy controller (DPC) app is added to a device outside of a managed context, the add account flow now prompts the user to install the appropriate WPC. This behavior also applies to accounts added via Settings > Accounts and in the initial device setup wizard.
Changes to specific DevicePolicyManager API behaviors:
Calling the setCameraDisabled() method affects the camera for the calling user only; calling it from the managed profile doesn’t affect camera apps running on the primary user.
In addition, the setKeyguardDisabledFeatures() method is now available for Profile Owners, as well as to Device Owners.
A Profile Owner can set these keyguard restrictions:
KEYGUARD_DISABLE_TRUST_AGENTS and KEYGUARD_DISABLE_FINGERPRINT, which affect the keyguard settings for the profile’s parent user.
KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS, which only affects notifications generated by applications in the managed profile.
The createAndInitializeUser() and createUser() methods have been deprecated.
The setScreenCaptureDisabled() method now also blocks the assist structure when an app of the given user is in the foreground.
EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM now defaults to SHA-256. SHA-1 is still supported for backwards compatibility but will be removed in future. EXTRA_PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM now only accepts SHA-256.
Device initializer APIs which existed in the Android 6.0 (API level 23) are now removed.
EXTRA_PROVISIONING_RESET_PROTECTION_PARAMETERS is removed so NFC bump provisioning cannot programmatically unlock a factory reset protected device.
You can now use the EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE extra to pass data to the device owner app during NFC provisioning of the managed device.
Android for Work APIs are optimized for M runtime permissions, including Work profiles, assist layer, and others. New DevicePolicyManager permission APIs don’t affect pre-M apps.
When users back out of the synchronous part of the setup flow initiated through an ACTION_PROVISION_MANAGED_PROFILE or ACTION_PROVISION_MANAGED_DEVICE intent, the system now returns a RESULT_CANCELED result code.
Changes to other APIs:
Data Usage: The android.app.usage.NetworkUsageStats class has been renamed NetworkStats.

Changes to global settings:
These settings can no longer be set via setGlobalSettings():
BLUETOOTH_ON
DEVELOPMENT_SETTINGS_ENABLED
MODE_RINGER
NETWORK_PREFERENCE
WIFI_ON
These global settings can now be set via setGlobalSettings():
WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值