本文實例講述了Android權限操做之uses-permission。分享給你們供你們參考,具體以下:html
咱們在安裝Android軟件的時候,系統會提示該軟件所須要的權限,相對於其餘系統,android的權限很是多。咱們在開發軟件的時候,也須要聲明相應的權限,好比但願軟件能發短信,須要聲明軟件調用短信的權限,不然軟件運行的時候就會報錯。android
Android的權限在AndroidManifest.xml文件裏配置。AndroidManifest文件中有四個標籤與permission有關,它們分別是 <permission>、 <permission-group> 、<permission-tree> 和 <uses-permission>。其中最經常使用的是 <uses-permission>,當咱們須要獲取某個權限的時候就必須在咱們的manifest文件中聲明<uses-permission>。數據庫
1
2
3
4
5
6
7
8
9
10
|
<?
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。後面三個標籤具體使用方法後續文章會有介紹。windows
<permission>定義方法以下:緩存
1
2
3
4
5
6
7
|
<
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這個屬性是必須聲明,告訴系統通知用戶的應用要求許可,或容許誰認爲得到許可的狀況下。permissionGroup這個是可選的,與<permission-group>配合使用。label, name和icon用於描述權限。 <permission>的用法後面也會再詳細分析。網絡
<uses-permission>是咱們用的最多的,官方文檔定義方式以下:app
1
|
<
uses-permission
android:name
=
"string"
/>
|
例如,短信和電話權限的定義:socket
1
2
|
<
uses-permission
android:name
=
"android.permission.CALL_PHONE"
/>
<
uses-permission
android:name
=
"android.permission.SEND_SMS"
/>
|
下面是收集到的 <uses-permission>的資料,方便用的時候查找:ide
android.permission.ACCESS_CHECKIN_PROPERTIES
容許讀寫訪問」properties」表在checkin數據庫中,改值能夠修改上傳( 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
容許程序建立模擬位置提供用於測試(Allowsan application to create mock location providers for testing)
android.permission.ACCESS_NETWORK_STATE
容許程序訪問有關GSM網絡信息(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網絡狀態信息(Allows applications to accessinformation about Wi-Fi networks)
android.permission.ADD_SYSTEM_SERVICE
容許程序發佈系統級服務(Allowsan application to publish system-level services).
android.permission.BATTERY_STATS
容許程序更新手機電池統計信息(Allowsan application to update the collected battery statistics)
android.permission.BLUETOOTH
容許程序鏈接到已配對的藍牙設備(Allowsapplications to connect to paired bluetooth devices)
android.permission.BLUETOOTH_ADMIN
容許程序發現和配對藍牙設備(Allowsapplications to discover and pair bluetooth devices)
android.permission.BRICK
請求可以禁用設備(很是危險)(Required to be able to disable thedevice (very *erous!).)
android.permission.BROADCAST_PACKAGE_REMOVED
容許程序廣播一個提示消息在一個應用程序包已經移除後(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
容許程序改變網絡鏈接狀態(Allowsapplications to change network connectivity state)
android.permission.CHANGE_WIFI_STATE
容許程序改變Wi-Fi鏈接狀態(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
容許程序返回狀態抓取信息從系統服務(Allowsan application to retrieve state dump information from system services.)
android.permission.EXPAND_STATUS_BAR
容許一個程序擴展收縮在狀態欄,android開發網提示應該是一個相似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開發網提示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開發網分析多是一個預留權限.
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
容許一個程序獲取信息有關當前或最近運行的任務,一個縮略的任務狀態,是否活動等等(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開發網提醒算是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
容許打開窗口使用系統用戶界面(Allowsan application to open windows that are for use by parts of the system userinterface. )
android.permission.INTERNET
容許程序打開網絡套接字(Allowsapplications to open network sockets)
android.permission.MANAGE_APP_TOKENS
容許程序管理(建立、催後、 z- order默認向z軸推移)程序引用在窗口管理器中(Allowsan application to manage (create, destroy, Z-order) application tokens in thewindow manager. )
android.permission.MASTER_CLEAR
目前尚未明確的解釋,android開發網分析多是清除一切數據,相似硬格機
android.permission.MODIFY_AUDIO_SETTINGS
容許程序修改全局音頻設置(Allowsan application to modify global audio settings)
android.permission.MODIFY_PHONE_STATE
容許修改話機狀態,如電源,人機接口等(Allowsmodification of the telephony state – power on, mmi, etc. )
android.permission.MOUNT_UNMOUNT_FILESYSTEMS
容許掛載和反掛載文件系統可移動存儲(Allowsmounting and unmounting file systems for removable storage. )
android.permission.PERSISTENT_ACTIVITY
容許一個程序設置他的activities顯示(Allow an application to make itsactivities persistent. )
android.permission.PROCESS_OUTGOING_CALLS
容許程序監視、修改有關播出電話(Allowsan application to monitor, modify, or abort outgoing calls)
android.permission.READ_CALENDAR
容許程序讀取用戶日曆數據(Allowsan application to read the user's calendar data.)
android.permission.READ_CONTACTS
容許程序讀取用戶聯繫人數據(Allowsan application to read the user's contacts data.)
android.permission.READ_FRAME_BUFFER
容許程序屏幕波或和更多常規的訪問幀緩衝數據(Allowsan application to take screen shots and more generally get access to the framebuffer data)
android.permission.READ_INPUT_STATE
容許程序返回當前按鍵狀態(Allowsan application to retrieve the current state of keys and switches. )
android.permission.READ_LOGS
容許程序讀取底層系統日誌文件(Allowsan application to read the low-level system log files. )
android.permission.READ_OWNER_DATA
容許程序讀取全部者數據(Allowsan application to read the owner's data)
android.permission.READ_SMS
容許程序讀取短信息(Allowsan application to read SMS messages.)
android.permission.READ_SYNC_SETTINGS
容許程序讀取同步設置(Allowsapplications to read the sync settings)
android.permission.READ_SYNC_STATS
容許程序讀取同步狀態(Allowsapplications to read the sync stats)
android.permission.REBOOT
請求可以從新啓動設備(Requiredto be able to reboot the device. )
android.permission.RECEIVE_BOOT_COMPLETED
容許一個程序接收到ACTION_BOOT_COMPLETED廣播在系統完成啓動(Allowsan application to receive the ACTION_BOOT_COMPLETED that is broadcast after thesystem finishes booting. )
android.permission.RECEIVE_MMS
容許一個程序監控將收到MMS彩信,記錄或處理(Allowsan application to monitor incoming MMS messages, to record or performprocessing on them. )
android.permission.RECEIVE_SMS
容許程序監控一個將收到短信息,記錄或處理(Allowsan application to monitor incoming SMS messages, to record or performprocessing on them.)
android.permission.RECEIVE_WAP_PUSH
容許程序監控將收到WAPPUSH信息(Allows an applicationto monitor incoming WAP push messages. )
android.permission.RECORD_AUDIO
容許程序錄制音頻(Allowsan application to record audio)
android.permission.REORDER_TASKS
容許程序改變Z軸排列任務(Allows an application to change theZ-order of tasks)
android.permission.RESTART_PACKAGES
容許程序從新啓動其餘程序(Allowsan application to restart other applications)
android.permission.SEND_SMS
容許程序發送SMS短信(Allows an application to send SMSmessages)
android.permission.SET_ACTIVITY_WATCHER
容許程序監控或控制activities已經啓動全局系統中(Allows an application to watch andcontrol how activities are started globally in the system.)
android.permission.SET_ALWAYS_FINISH
容許程序控制是否活動間接完成在處於後臺時(Allowsan application to control whether activities are immediately finished when putin the background.)
android.permission.SET_ANIMATION_SCALE
修改全局信息比例(Modifythe global animation scaling factor.)
android.permission.SET_DEBUG_APP
配置一個程序用於調試(Configurean application for debugging.)
android.permission.SET_ORIENTATION
容許底層訪問設置屏幕方向和實際旋轉(Allowslow-level access to setting the orientation (actually rotation) of the screen.)
android.permission.SET_PREFERRED_APPLICATIONS
容許一個程序修改列表參數PackageManager.addPackageToPreferred()和PackageManager.removePackageFromPreferred()方法(Allowsan application to modify the list of preferred applications with thePackageManager.addPackageToPreferred() andPackageManager.removePackageFromPreferred() methods.)
android.permission.SET_PROCESS_FOREGROUND
容許程序當前運行程序強行到前臺(Allowsan application to force any currently running process to be in the foreground.)
android.permission.SET_PROCESS_LIMIT
容許設置最大的運行進程數量(Allowsan application to set the maximum number of (not needed) application processesthat can be running. )
android.permission.SET_TIME_ZONE
容許程序設置時間區域(Allowsapplications to set the system time zone)
android.permission.SET_WALLPAPER
容許程序設置壁紙(Allowsapplications to set the wallpaper )
android.permission.SET_WALLPAPER_HINTS
容許程序設置壁紙hits(Allowsapplications to set the wallpaper hints)
android.permission.SIGNAL_PERSISTENT_PROCESSES
容許程序請求發送信號到全部顯示的進程中(Allowan application to request that a signal be sent to all persistent processes)
android.permission.STATUS_BAR
容許程序打開、關閉或禁用狀態欄及圖標Allowsan application to open, close, or disable the status bar and its icons.
android.permission.SUBSCRIBED_FEEDS_READ
容許一個程序訪問訂閱RSSFeed內容提供(Allows an applicationto allow access the subscribed feeds ContentProvider. )
android.permission.SUBSCRIBED_FEEDS_WRITE
系統暫時保留改設置,android開發網認爲將來版本會加入該功能。
android.permission.SYSTEM_ALERT_WINDOW
容許一個程序打開窗口使用TYPE_SYSTEM_ALERT,顯示在其餘全部程序的頂層(Allowsan application to open windows using the type TYPE_SYSTEM_ALERT, shown on topof all other applications. )
android.permission.VIBRATE
容許訪問振動設備(Allowsaccess to the vibrator)
android.permission.WAKE_LOCK
容許使用PowerManager的 WakeLocks保持進程在休眠時從屏幕消失(Allows using PowerManager WakeLocks to keep
processor from sleeping or screen fromdimming)
android.permission.WRITE_APN_SETTINGS
容許程序寫入API設置(Allows applications to write the apnsettings)
android.permission.WRITE_CALENDAR
容許一個程序寫入但不讀取用戶日曆數據(Allowsan application to write (but not read) the user's calendar data. )
android.permission.WRITE_CONTACTS
容許程序寫入但不讀取用戶聯繫人數據(Allowsan application to write (but not read) the user's contacts data. )
android.permission.WRITE_GSERVICES
容許程序修改Google服務地圖(Allows an application to modify theGoogle service map. )
android.permission.WRITE_OWNER_DATA
容許一個程序寫入但不讀取全部者數據(Allowsan application to write (but not read) the owner's data.)
android.permission.WRITE_SETTINGS
容許程序讀取或寫入系統設置(Allowsan application to read or write the system settings. )
android.permission.WRITE_SMS
容許程序寫短信(Allowsan application to write SMS messages)
android.permission.WRITE_SYNC_SETTINGS
容許程序寫入同步設置(Allowsapplications to write the sync settings)
PS:關於AndroidManifest.xml文件相關屬性功能可參考本站在線工具:
Android Manifest功能與權限描述大全:
http://tools.jb51.net/table/AndroidManifest
更多關於Android相關內容感興趣的讀者可查看本站專題:《Android開發入門與進階教程》、《Android調試技巧與常見問題解決方法彙總》、《Android多媒體操做技巧彙總(音頻,視頻,錄音等)》、《Android基本組件用法總結》、《Android視圖View技巧總結》、《Android佈局layout技巧總結》及《Android控件用法總結》
但願本文所述對你們Android程序設計有所幫助。