本文實例講述了Android權限操作之uses-permission。分享給大家供大家參考,具體如下:
我們在安裝Android軟件的時候,系統(tǒng)會提示該軟件所需要的權限,相對于其他系統(tǒng),android的權限非常多。我們在開發(fā)軟件的時候,也需要聲明相應的權限,比如希望軟件能發(fā)短信,需要聲明軟件調(diào)用短信的權限,否則軟件運行的時候就會報錯。
Android的權限在AndroidManifest.xml文件里配置。AndroidManifest文件中有四個標簽與permission有關,它們分別是 <permission>、 <permission-group> 、<permission-tree> 和 <uses-permission>。其中最常用的是 <uses-permission>,當我們需要獲取某個權限的時候就必須在我們的manifest文件中聲明<uses-permission>。
<?xml version="1.0" encoding="utf-8"?><manifest> <application> </application> <uses-permission /> <permission /> <permission-tree /> <permission-group /> ...</manifest>
<permission>和 <uses-permission>的作用相似,兩者之間的不同之處,<uses-permission>是android預定義的權限,<permission>是自己定義的權限。 <permission>用的相對較少,<permission-group> <permission-tree>這兩個標簽就更少見了,簡單說<permission-group> 就是聲明一個標簽,該標簽代表了一組permissions,而<permission-tree>是為一組permissions聲明了一個namespace。后面三個標簽具體使用方法后續(xù)文章會有介紹。
<permission>定義方法如下:
<permission android:description="string resource" android:icon="drawable resource" android:label="string resource" android:name="string" android:permissionGroup="string" android:protectionLevel=["normal" | "dangerous" | "signature" | "signatureOrSystem"] />
上面代碼來自官方文檔:http://developer.android.com/guide/topics/manifest/permission-element.html。propectionLevel這個屬性是必須聲明,告訴系統(tǒng)通知用戶的應用要求許可,或允許誰認為獲得許可的情況下。permissionGroup這個是可選的,與<permission-group>配合使用。label, name和icon用于描述權限。 <permission>的用法后面也會再詳細分析。
<uses-permission>是我們用的最多的,官方文檔定義方式如下:
<uses-permission android:name="string" />
例如,短信和電話權限的定義:
<uses-permission android:name="android.permission.CALL_PHONE" /><uses-permission android:name="android.permission.SEND_SMS"/>
下面是收集到的 <uses-permission>的資料,方便用的時候查找:
android.permission.ACCESS_CHECKIN_PROPERTIES
允許讀寫訪問”properties”表在checkin數(shù)據(jù)庫中,改值可以修改上傳( Allowsread/write access to the “properties” table in the checkin database, to changevalues that get uploaded)
android.permission.ACCESS_COARSE_LOCATION
允許一個程序訪問CellID或WiFi熱點來獲取粗略的位置(Allowsan application to access coarse (e.g., Cell-ID, WiFi) location)
android.permission.ACCESS_FINE_LOCATION
允許一個程序訪問精良位置(如GPS) (Allows an application to accessfine (e.g., GPS) location)
android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
允許應用程序訪問額外的位置提供命令(Allowsan application to access extra location provider commands)
android.permission.ACCESS_MOCK_LOCATION
允許程序創(chuàng)建模擬位置提供用于測試(Allowsan application to create mock location providers for testing)
android.permission.ACCESS_NETWORK_STATE
允許程序訪問有關GSM網(wǎng)絡信息(Allows applications to accessinformation about networks)
android.permission.ACCESS_SURFACE_FLINGER
允許程序使用SurfaceFlinger底層特性(Allows an application to useSurfaceFlinger's low level features)
android.permission.ACCESS_WIFI_STATE
允許程序訪問Wi-Fi網(wǎng)絡狀態(tài)信息(Allows applications to accessinformation about Wi-Fi networks)
android.permission.ADD_SYSTEM_SERVICE
允許程序發(fā)布系統(tǒng)級服務(Allowsan application to publish system-level services).
android.permission.BATTERY_STATS
允許程序更新手機電池統(tǒng)計信息(Allowsan application to update the collected battery statistics)
android.permission.BLUETOOTH
允許程序連接到已配對的藍牙設備(Allowsapplications to connect to paired bluetooth devices)
android.permission.BLUETOOTH_ADMIN
允許程序發(fā)現(xiàn)和配對藍牙設備(Allowsapplications to discover and pair bluetooth devices)
android.permission.BRICK
請求能夠禁用設備(非常危險)(Required to be able to disable thedevice (very *erous!).)
android.permission.BROADCAST_PACKAGE_REMOVED
允許程序廣播一個提示消息在一個應用程序包已經(jīng)移除后(Allowsan application to broadcast a notification that an application
package has been removed)
android.permission.BROADCAST_STICKY
允許一個程序廣播常用intents(Allowsan application to broadcast sticky intents)
android.permission.CALL_PHONE
允許一個程序初始化一個電話撥號不需通過撥號用戶界面需要用戶確認(Allowsan application to initiate a phone call without going through the Dialer userinterface for the user to confirm the call being placed.)
android.permission.CALL_PRIVILEGED
允許一個程序撥打任何號碼,包含緊急號碼無需通過撥號用戶界面需要用戶確認(Allowsan application to call any phone number, including emergency numbers, withoutgoing through the Dialer user interface for the user to confirm the call beingplaced)
android.permission.CAMERA
請求訪問使用照相設備(Requiredto be able to access the camera device. )
android.permission.CHANGE_COMPONENT_ENABLED_STATE
允許一個程序是否改變一個組件或其他的啟用或禁用(Allowsan application to change whether an application component (other than its own)is enabled or not. )
android.permission.CHANGE_CONFIGURATION
允許一個程序修改當前設置,如本地化(Allowsan application to modify the current configuration, such as locale. )
android.permission.CHANGE_NETWORK_STATE
允許程序改變網(wǎng)絡連接狀態(tài)(Allowsapplications to change network connectivity state)
android.permission.CHANGE_WIFI_STATE
允許程序改變Wi-Fi連接狀態(tài)(Allows applications to change Wi-Ficonnectivity state)
android.permission.CLEAR_APP_CACHE
允許一個程序清楚緩存從所有安裝的程序在設備中(Allowsan application to clear the caches of all installed applications on the device.)
android.permission.CLEAR_APP_USER_DATA
允許一個程序清除用戶設置(Allowsan application to clear user data)
android.permission.CONTROL_LOCATION_UPDATES
允許啟用禁止位置更新提示從無線模塊(Allowsenabling/disabling location update notifications from the radio. )
android.permission.DELETE_CACHE_FILES
允許程序刪除緩存文件(Allowsan application to delete cache files)
android.permission.DELETE_PACKAGES
允許一個程序刪除包(Allowsan application to delete packages)
android.permission.DEVICE_POWER
允許訪問底層電源管理(Allowslow-level access to power management)
android.permission.DIAGNOSTIC
允許程序RW診斷資源(Allows applications to RW to diagnosticresources. )
android.permission.DISABLE_KEYGUARD
允許程序禁用鍵盤鎖(Allowsapplications to disable the keyguard )
android.permission.DUMP
允許程序返回狀態(tài)抓取信息從系統(tǒng)服務(Allowsan application to retrieve state dump information from system services.)
android.permission.EXPAND_STATUS_BAR
允許一個程序擴展收縮在狀態(tài)欄,android開發(fā)網(wǎng)提示應該是一個類似Windows Mobile中的托盤程序(Allows an application to expand orcollapse the status bar. )
android.permission.FACTORY_TEST
作為一個工廠測試程序,運行在root用戶(Run as a manufacturer test application,running as the root user. )
android.permission.FLASHLIGHT
訪問閃光燈,android開發(fā)網(wǎng)提示HTC Dream不包含閃光燈(Allowsaccess to the flashlight )
android.permission.FORCE_BACK
允許程序強行一個后退操作是否在頂層activities(Allowsan application to force a BACK operation on whatever is the top activity. )
android.permission.FOTA_UPDATE
暫時不了解這是做什么使用的,android開發(fā)網(wǎng)分析可能是一個預留權限.
android.permission.GET_ACCOUNTS
訪問一個帳戶列表在AccountsService中(Allows access to thelist of accounts in the Accounts Service)
android.permission.GET_PACKAGE_SIZE
允許一個程序獲取任何package占用空間容量(Allows an application to find out thespace used by any package. )
android.permission.GET_TASKS
允許一個程序獲取信息有關當前或最近運行的任務,一個縮略的任務狀態(tài),是否活動等等(Allowsan application to get information about the currently or recently runningtasks: a thumbnail representation of the tasks, what activities are running init, etc.)
android.permission.HARDWARE_TEST
允許訪問硬件(Allowsaccess to hardware peripherals. )
android.permission.INJECT_EVENTS
允許一個程序截獲用戶事件如按鍵、觸摸、軌跡球等等到一個時間流,android開發(fā)網(wǎng)提醒算是hook技術吧(Allowsan application to inject user events (keys, touch, trackball) into the eventstream and deliver them to ANY window.)
android.permission.INSTALL_PACKAGES
允許一個程序安裝packages(Allowsan application to install packages. )
android.permission.INTERNAL_SYSTEM_WINDOW
允許打開窗口使用系統(tǒng)用戶界面(Allowsan application to open windows that are for use by parts of the system userinterface. )
android.permission.INTERNET
允許程序打開網(wǎng)絡套接字(Allowsapplications to open network sockets)
android.permission.MANAGE_APP_TOKENS
允許程序管理(創(chuàng)建、催后、 z- order默認向z軸推移)程序引用在窗口管理器中(Allowsan application to manage (create, destroy, Z-order) application tokens in thewindow manager. )
android.permission.MASTER_CLEAR
目前還沒有明確的解釋,android開發(fā)網(wǎng)分析可能是清除一切數(shù)據(jù),類似硬格機
android.permission.MODIFY_AUDIO_SETTINGS
允許程序修改全局音頻設置(Allowsan application to modify global audio settings)
android.permission.MODIFY_PHONE_STATE
允許修改話機狀態(tài),如電源,人機接口等(Allowsmodification of the telephony state
主站蜘蛛池模板:
镇康县|
科尔|
塘沽区|
闻喜县|
东莞市|
文成县|
阳原县|
石泉县|
肥东县|
桑植县|
理塘县|
谢通门县|
哈尔滨市|
潜山县|
宜川县|
荔波县|
安义县|
巢湖市|
永川市|
桐城市|
从化市|
茌平县|
岳普湖县|
汽车|
循化|
岑溪市|
台江县|
同仁县|
桦南县|
芦溪县|
枣阳市|
遂川县|
讷河市|
东阳市|
弋阳县|
贵溪市|
兴化市|
邵武市|
淮北市|
博爱县|
隆安县|