Android6.0的重要变化

来源:互联网 发布:java int转long 编辑:程序博客网 时间:2024/04/29 19:07
一.通知(Notifications)
此版本移除了Notification.setLatestEventInfo()方法。用Notification.Builder类来构造通知,在需要反复更新通知的情况下,保存并重用Notification.Builder的实例;在获取更新后的Notification实例时,调用其build()方法
adb shell dumpsys notification命令不再输出你的通知文本,而adb shell dumpsys notification --noredact命令将输出一个notification对象的文本


notification.setLatestEventInfo(Context context , CharSequence contentTitle,CharSequence  contentText,PendingIntent contentIntent);

功能: 显示在拉伸状态栏中的Notification属性,点击后将发送PendingIntent对象。

参数: context             上下文环境

             contentTitle      状态栏中的大标题

             contentText      状态栏中的小标题

             contentIntent    点击后将发送PendingIntent对象


更换为:
Notification noti = new Notification.Builder(mContext).setContentTitle("New mail from " + sender.toString()).setContentText(subject).setSmallIcon(R.drawable.new_mail).setContentIntent(pendingIntent)
.build();
二、移除Appache的HTTP Client(Apache HTTP Client Removal)

  Android6.0版本移除了对Appache的HTTP client的支持。如果你的app的目标版本是Android2.3(API level 9)或者更高,请使用HttpURLConnection类进行替换。此类采用了透明压缩(transparent compression)和响应缓存(response caching),最小化电量消耗。如果你希望继续使用Appache Http API,请修改你的build.gradle文件,增加如下:

[html] view plain copy
  1. android {  
  2.     useLibrary 'org.apache.http.legacy'  
  3. }  
三,运行时权限检查(Runtime Permisssions)
    此次发布引入了一个新的权限管理模型,使得用户能够在运行时控制应用的权限。这个模型一方面提高了用户在权限控制的可视化程度和管理粒度,另一方面也改善了应用安装和自动更新的流程。用户能够对已安装的应用的各个权限进行独立的授权(grant)和禁用(revoke)。
     作为开发者,当你的app的目标版本(target)为Android6.0(API 23)或更高时,请确保在运行时进行权限的检查和请求。其中,新的方法checkSelfPermission()可以用来判断你的应用是否被授予了权限,而requestPermissions()可请求权限。即使你app的目标版本在android6.0以下,也应该在新的权限管理模型下测试你的应用。
让你的应用支持新的权限管理模型,以及获得更多的官方提示,可查看Working with System Permissionss(https://developer.android.com/training/permissions/index.html)和 Permissions Best Practices(https://developer.android.com/training/permissions/best-practices.html#testing)
0 0