Android 6.0的執行時許可權 批量申請
Android 6.0,代號棉花糖,自發布伊始,其主要的特徵執行時許可權就很受關注。因為這一特徵不僅改善了使用者對於應用的使用體驗,還使得應用開發者在實踐開發中需要做出改變。
沒有深入瞭解執行時許可權的開發者通常會有很多疑問,比如什麼是執行時許可權,哪些是執行時的許可權,我的應用是不是會在6.0系統上各種崩潰呢,如何才能支援執行時許可權機制呢。本文講嘗試回答這一些問題,希望讀者閱讀完成之後,都能找到較為完美的答案。
許可權一刀切
在6.0以前的系統,都是許可權一刀切的處理方式,只要使用者安裝,Manifest申請的許可權都會被賦予,並且安裝後許可權也撤銷不了。
這種情況下,當我們從Google Play安裝一個應用,在安裝之前會得到這樣的許可權提示資訊。
當上述對話方塊彈出後,使用者只有兩種選擇:
- 我信任你,即使有敏感許可權
- 你一個**應用,要這個許可權幹嘛,我還是不安裝了。
所以,這種一刀切的處理方式還是有弊端的,我們沒有辦法只允許某些許可權或者拒絕某些許可權。
棉花糖執行時許可權
從棉花糖開始,Android系統引入了新的許可權機制,即本文要講的執行時許可權。
何為執行時許可權呢?舉個栗子,以某個需要拍照的應用為例,當執行時許可權生效時,其Camera許可權不是在安裝後賦予,而是在應用執行的時候進行請求許可權(比如當用戶按下”相機拍照“按鈕後)看到的效果則是這樣的
接下來,對於Camera許可權的處理完全權交給使用者。是不是有點像蘋果系統的處理呢,不要說這是抄襲,暫且稱為師夷長技以制夷。
許可權的分組
Android中有很多許可權,但並非所有的許可權都是敏感許可權,於是6.0系統就對許可權進行了分類,一般為下述幾類
- 正常(Normal Protection)許可權
- 危險(Dangerous)許可權
- 特殊(Particular)許可權
- 其他許可權(一般很少用到)
正常許可權
正常許可權具有如下的幾個特點
- 對使用者隱私沒有較大影響或者不會打來安全問題。
- 安裝後就賦予這些許可權,不需要顯示提醒使用者,使用者也不能取消這些許可權。
正常許可權列表
<span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">1</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">2</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">3</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">4</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">5</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">6</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">7</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">8</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">9</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">10</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">11</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">12</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">13</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">14</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">15</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">16</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">17</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">18</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">19</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">20</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">21</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">22</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">23</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">24</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">25</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">26</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">27</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">28</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">29</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">30</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">31</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">32</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">33</span> |
|
上述的許可權基本設計的是關於網路,藍芽,時區,快捷方式等方面,只要在Manifest指定了這些許可權,就會被授予,並且不能撤銷。
特殊許可權
這裡講特殊許可權提前講一下,因為這個相對來說簡單一些。
特殊許可權,顧名思義,就是一些特別敏感的許可權,在Android系統中,主要由兩個
- SYSTEM_ALERT_WINDOW,設定懸浮窗,進行一些黑科技
- WRITE_SETTINGS 修改系統設定
關於上面兩個特殊許可權的授權,做法是使用startActivityForResult
啟動授權介面來完成。
請求SYSTEM_ALERT_WINDOW
<span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">1</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">2</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">3</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">4</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">5</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">6</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">7</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">8</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">9</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">10</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">11</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">12</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">13</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">14</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">15</span> <span class="line-number" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; color: rgb(147, 161, 161) !important;">16</span> |
|
相關推薦
Android 6.0執行時許可權申請和一些坑
1.概述 大家知道在Android6.0(Api23)之前,使用者許可權的申請都是在AndroidManifest.xml 宣告的,而在6.0之後,對某些涉及到使用者隱私的許可權可在執行時根據使用者的需要動態授予。如果你的應用設定targetSdkVersio
Android 6.0執行時許可權勾選不再詢問後該如何處理?
Android 6.0執行時許可權勾選不再詢問後該如何處理? 當第一次請求許可權申請被拒絕後再進行第二次申請時,對話方塊中會多出一個 不再詢問 的複選框。如果勾選了該複選框並且拒絕請求,那麼以後將無法再申請該許可權。也就是說在呼叫 requestPermissions() 後,onRequest
Android 6 0 執行時許可權處理
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
Android 6 0 執行時許可權處理完全解析
一、概述ok,本篇文章目的之一就是對執行時許可權處理的一個介紹,以及對目前許可權相關的庫的一些瞭解。當然非常推薦閱讀官網許可權相關文章:本文也是在上述文章基礎上理解、實驗以及封裝。二、執行時許可權的變化及特點對於6.0以下的許可權及在安裝的時候,根據許可權宣告產生一個
以呼叫系統相機拍照為例瞭解Android 6.0執行時許可權
首先扯點別的,聽說這個週末是好天氣,想約她一起去公園賞賞梅花,只有我自己估計她也不一定去啊,哈哈。 在android6.0及以上系統,Android在安裝一個應用的時候不再需要列出一大堆許可權,讓使用者點選同意以後才可以安裝。Instead, 當應用在執行的時
談談Android 6.0執行時許可權理解
前言 谷歌在2015年8月份時候,釋出了Android 6.0版本,代號叫做“棉花糖”(Marshmallow ),其中的很大的一部分變化,是在使用者許可權授權上,或許是感覺之前預設授權的不合理,現在6.0出來,使得使用者許可權授權變得合理。這可能也是參考IOS系統的,只有在使用者需要使用許可權的時候,才
Android 6.0 執行時許可權處理
執行時許可權介紹 Android 6.0在我們原有的AndroidManifest.xml宣告許可權的基礎上, 又新增了執行時許可權動態檢測,以下許可權都需要在執行時判斷: 執行時許可權處理 Android6.0系統預設為targetSdkVersion小於23的應用預設授予了所申請的所有許可權,
Android 6.0 執行時許可權管理最佳實踐
這是一篇遲來的部落格,Android M已經發布一年多了(6.0的變化),在Android M中許可權系統被重新設計,發生了顛覆性的變化,很多人把握不好這個變化,一是對這個許可權策略和套路還沒有摸透,二是沒有一個很好的實踐來支撐,在我的技術開發群裡很多人問我
android 6.0執行時許可權應用之相簿圖片選取
public class MainActivity extends AppCompatActivity { public static final int REQUEST_CODE=200; public static final int REQUEST_C
Android 6.0 執行時許可權處理完全解析
一、概述 ok,本篇文章目的之一就是對執行時許可權處理的一個介紹,以及對目前許可權相關的庫的一些瞭解。 當然非常推薦閱讀官網許可權相關文章: 本文也是在上述文章基礎上理解、實驗以及封裝。 二、執行時許可權的變化及特點 對於6.0以下
Android 6.0 執行時許可權檢查分析
Android版本升級到6.0之後,為了一改往日安全受人詬病的形象,將許可權授權的安裝時授予的基礎上,對於一部分危險的許可權採用動態控制授權的方式。類似國內手機安全助手許可權控制的功能。一、許可權控制組: 以上的9組許可權在本次修改的範圍之內,可能有人要問了,明明有一些許可
Android 6.0執行時許可權第三方庫的使用-----RxPermissions
執行時許可權的講解在前一篇部落格已經算是說的比較清楚了,這裡就不說了,如果對6.0這個新特性不是很瞭解的朋友建議先看看(地址:http://blog.csdn.net/qq_33923079/article/details/53428756),那麼本篇就直接說怎
Android 6.0 執行時許可權
什麼時候需要考慮執行時許可權 執行時許可權是Android6.0推出的安全機制,當你的app執行在 Android 6.0 及以上裝置上,使用危險許可權(下面介紹)的時候。 既targetSdkVer
Android 6.0 執行時許可權機制瞭解與應用
目前的安卓手機系統版本普遍都在5.0、6.0以上甚至7.0、8.0。在Andorid 6.0系統之後開始引入了執行時許可權這個機制。許可權機制在android中原本就有的在manifest中編寫的permission標籤,而新增的執行時許可權則是將容易暴露使用者隱私的一些
Android 6.0的執行時許可權 批量申請
Android 6.0,代號棉花糖,自發布伊始,其主要的特徵執行時許可權就很受關注。因為這一特徵不僅改善了使用者對於應用的使用體驗,還使得應用開發者在實踐開發中需要做出改變。 沒有深入瞭解執行時許可權的開發者通常會有很多疑問,比如什麼是執行時許可權,哪些是執行時
Android 6.0執行時獲取許可權詳解
最近在工作過程中會遇到,明明已經在AndroidManifest.xml中配置了許可權,但是就是沒有作用,百度了之後才發現現在在應用系統大於等於6.0的手機上面,需要動態的獲取許可權。就是當你需要這個許可權的時候,需要手機給使用者一個提示選擇是否同意開啟這個許
6.0執行時許可權與targetSdkVersion選擇
targetSDKVersion 簡單來說就代表著你的App能夠適配的系統版本,意味著你的App在這個版本的手機上做了充分的 前向 相容性處理和實際測試。其實我們寫程式碼時都是經常幹這麼一件事,就是 if(Build.VERSION.SDK_INT >= 23) {
安卓6.0執行時許可權處理方案
許可權檢查一般放在APP的入口,比如說閃屏頁splashactivity中或者baseapplication中。 其中需要兩個類,一個是PermissionChecker,一個是PermissionsActivity。第一個是用來檢測當前是否已經獲取到了申請
android 6.0 以後在 Fragment 中申請執行時許可權無法回撥 onRequestPermissionsResult
一般情況下我們在activity中申請許可權,然後在onRequestPermissionsResult中處理回撥,但是在fragment中申請許可權時,在onRequestPermissionsResult中無法收到回撥方法。 下面提供兩種解決辦法: 第一
Android學習筆記-Android6.0執行時許可權
Android許可權機制,在Android6.0之前,其實一直很簡單,在AndroidManifest.xml中進行許可權宣告,通過一個Intent呼叫即可。 以打電話為例: <uses-permission android:name="andro