Android6.0的重要變化

一.通知(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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章