1. 程式人生 > >Android Permission許可權列表以及Android6.0以後獲取許可權

Android Permission許可權列表以及Android6.0以後獲取許可權

Android程式在執行某些敏感問題時需要獲取許可權,比如獲取通訊錄許可權,獲取相機許可權,獲取定位許可權等等,針對Android6.0以前,只需要在AndroidManifest.xml檔案中使用類似於
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
的程式碼即可,但是到了Android6.0以後,由於安全機制又有增強,所以需要在程式碼中動態的獲取要是用的許可權,所有程式碼分為兩個部分: 申請授權和回撥 以下是申請授權
// 拍照的許可權
            if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(WindDetailEditActivity.this,
                        new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE},
                        1);
            } else {
                // 需要執行的方法
            }
下面是回撥
/**
     * 動態獲取許可權回撥
     *
     * @param requestCode  請求碼
     * @param permissions  許可權陣列
     * @param grantResults 結果
     */
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        switch (requestCode) {
            case 1:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    // 需要執行的方法
                } else {
                    Toast.makeText(this, "請在設定中開啟相機許可權", Toast.LENGTH_SHORT).show();
                }
                break;
            case 2:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    // 需要執行的方法
                } else {
                    Toast.makeText(this, "請在設定中開啟相簿許可權", Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }

permission列表如下: 1、android.permission.ACCESS_CHECKIN_PROPERTIES 允許讀寫訪問”properties”表在 checkin資料庫中,改值可以修改上傳( Allows read/write access to the “properties” table in the checkin database, to change values that get uploaded) 2、android.permission.ACCESS_COARSE_LOCATION 允許一個程式訪問CellID或WiFi熱點來獲取粗略的位置(Allows an application to access coarse (e.g., Cell-ID, WiFi) location) 3、android.permission.ACCESS_FINE_LOCATION 允許一個程式訪問精良位置(如GPS) (Allows an application to access fine (e.g., GPS) location) 4、android.permission.ACCESS_LOCATION_EXTRA_COMMANDS 允許應用程式訪問額外的位置提供命令(Allows an application to access extra location provider commands) 5、android.permission.ACCESS_MOCK_LOCATION 允許程式建立模擬位置提供用於測試(Allows an application to create mock location providers for testing) 6、android.permission.ACCESS_NETWORK_STATE 允許程式訪問有關GSM網路資訊(Allows applications to access information about networks) 7、android.permission.ACCESS_SURFACE_FLINGER 允許程式使用SurfaceFlinger底層特性 (Allows an application to use SurfaceFlinger’s low level features) 8、android.permission.ACCESS_WIFI_STATE 允許程式訪問Wi-Fi網路狀態資訊(Allows applications to access information about Wi-Fi networks) 9、android.permission.ADD_SYSTEM_SERVICE 允許程式釋出系統級服務(Allows an application to publish system-level services). 10、android.permission.BATTERY_STATS 允許程式更新手機電池統計資訊(Allows an application to update the collected battery statistics) 11、android.permission.BLUETOOTH 允許程式連線到已配對的藍芽裝置(Allows applications to connect to paired bluetooth devices) 12、android.permission.BLUETOOTH_ADMIN 允許程式發現和配對藍芽裝置(Allows applications to discover and pair bluetooth devices) 13、android.permission.BRICK 請求能夠禁用裝置(非常危險)(Required to be able to disable the device (very *erous!).) 14、android.permission.BROADCAST_PACKAGE_REMOVED 允許程式廣播一個提示訊息在一個應用程式包已經移除後(Allows an application to broadcast a notification that an application package has been removed) 15、android.permission.BROADCAST_STICKY 允許一個程式廣播常用intents(Allows an application to broadcast sticky intents) 16、android.permission.CALL_PHONE 允許一個程式初始化一個電話撥號不需通過撥號使用者介面需要使用者確認 (Allows an application to initiate a phone call without going through the Dialer user interface for the user to confirm the call being placed.) 17、android.permission.CALL_PRIVILEGED 允許一個程式撥打任何號碼,包含緊急號碼無需通過撥號使用者介面需要使用者確認 (Allows an application to call any phone number, including emergency numbers, without going through the Dialer user interface for the user to confirm the call being placed) 18、android.permission.CAMERA 請求訪問使用照相裝置(Required to be able to access the camera device. ) 19、android.permission.CHANGE_COMPONENT_ENABLED_STATE 允許一個程式是否改變一個元件或其他的啟用或禁用(Allows an application to change whether an application component (other than its own) is enabled or not. ) 20、android.permission.CHANGE_CONFIGURATION 允許一個程式修改當前設定,如本地化(Allows an application to modify the current configuration, such as locale. ) 21、android.permission.CHANGE_NETWORK_STATE 允許程式改變網路連線狀態(Allows applications to change network connectivity state) 22、android.permission.CHANGE_WIFI_STATE 允許程式改變Wi-Fi連線狀態(Allows applications to change Wi-Fi connectivity state) 23、android.permission.CLEAR_APP_CACHE 允許一個程式清楚快取從所有安裝的程式在裝置中(Allows an application to clear the caches of all installed applications on the device. ) 24、android.permission.CLEAR_APP_USER_DATA 允許一個程式清除使用者設定(Allows an application to clear user data) 25、android.permission.CONTROL_LOCATION_UPDATES 允許啟用禁止位置更新提示從無線模組 (Allows enabling/disabling location update notifications from the radio. ) 26、android.permission.DELETE_CACHE_FILES 允許程式刪除快取檔案(Allows an application to delete cache files) 27、android.permission.DELETE_PACKAGES 允許一個程式刪除包(Allows an application to delete packages) 28、android.permission.DEVICE_POWER 允許訪問底層電源管理(Allows low-level access to power management) 29、android.permission.DIAGNOSTIC 允許程式RW診斷資源(Allows applications to RW to diagnostic resources. ) 30、android.permission.DISABLE_KEYGUARD 允許程式禁用鍵盤鎖(Allows applications to disable the keyguard ) 31、android.permission.DUMP 允許程式返回狀態抓取資訊從系統服務(Allows an application to retrieve state dump information from system services.) 32、android.permission.EXPAND_STATUS_BAR 允許一個程式擴充套件收縮在狀態列,
Android開發
網提示應該是一個類似Windows Mobile中的托盤程式(Allows an application to expand or collapse the status bar. ) 33、android.permission.FACTORY_TEST 作為一個工廠測試程式,執行在root使用者(Run as a manufacturer test application, running as the root user. ) 34、android.permission.FLASHLIGHT 訪問閃光燈,android開發網提示HTC Dream不包含閃光燈(Allows access to the flashlight ) 35、android.permission.FORCE_BACK 允許程式強行一個後退操作是否在頂層activities(Allows an application to force a BACK operation on whatever is the top activity. ) 36、android.permission.FOTA_UPDATE 暫時不瞭解這是做什麼使用的,android開發網分析可能是一個預留許可權. 37、android.permission.GET_ACCOUNTS 訪問一個帳戶列表在Accounts Service中(Allows access to the list of accounts in the Accounts Service) 38、android.permission.GET_PACKAGE_SIZE 允許一個程式獲取任何package佔用空間容量(Allows an application to find out the space used by any package. ) 39、android.permission.GET_TASKS 允許一個程式獲取資訊有關當前或最近執行的任務,一個縮略的任務狀態,是否活動等等(Allows an application to get information about the currently or recently running tasks: a thumbnail representation of the tasks, what activities are running in it, etc.) 40、android.permission.HARDWARE_TEST 允許訪問硬體(Allows access to hardware peripherals. ) 41、android.permission.INJECT_EVENTS 允許一個程式截獲使用者事件如按鍵、觸控、軌跡球等等到一個時間流,Android 開發網提醒算是hook技術吧(Allows an application to inject user events (keys, touch, trackball) into the event stream and deliver them to ANY window.) 42、android.permission.INSTALL_PACKAGES 允許一個程式安裝packages(Allows an application to install packages. ) 43、android.permission.INTERNAL_SYSTEM_WINDOW 允許開啟視窗使用系統使用者介面(Allows an application to open windows that are for use by parts of the system user interface. ) 44、android.permission.INTERNET 允許程式開啟網路套接字(Allows applications to open network sockets) 45、android.permission.MANAGE_APP_TOKENS 允許程式管理(建立、催後、 z- order預設向z軸推移)程式引用在視窗管理器中(Allows an application to manage (create, destroy, Z-order) application tokens in the window manager. ) 46、android.permission.MASTER_CLEAR 目前還沒有明確的解釋,android開發網分析可能是清除一切資料,類似硬格機 47、android.permission.MODIFY_AUDIO_SETTINGS 允許程式修改全域性音訊設定(Allows an application to modify global audio settings) 48、android.permission.MODIFY_PHONE_STATE 允許修改話機狀態,如電源,人機介面等(Allows modification of the telephony state ? power on, mmi, etc. ) 49、android.permission.MOUNT_UNMOUNT_FILESYSTEMS 允許掛載和反掛載檔案系統可移動儲存 (Allows mounting and unmounting file systems for removable storage. ) 50、android.permission.PERSISTENT_ACTIVITY 允許一個程式設定他的activities顯示 (Allow an application to make its activities persistent. ) 51、android.permission.PROCESS_OUTGOING_CALLS 允許程式監視、修改有關播出電話(Allows an application to monitor, modify, or abort outgoing calls) 52、android.permission.READ_CALENDAR 允許程式讀取使用者日曆資料(Allows an application to read the user’s calendar data.) 53、android.permission.READ_CONTACTS 允許程式讀取使用者聯絡人資料(Allows an application to read the user’s contacts data.) 54、android.permission.READ_FRAME_BUFFER 允許程式螢幕波或和更多常規的訪問幀緩衝資料(Allows an application to take screen shots and more generally get access to the frame buffer data) 55、android.permission.READ_INPUT_STATE 允許程式返回當前按鍵狀態(Allows an application to retrieve the current state of keys and switches. ) 56、android.permission.READ_LOGS 允許程式讀取底層系統日誌檔案(Allows an application to read the low-level system log files. ) 57、android.permission.READ_OWNER_DATA 允許程式讀取所有者資料(Allows an application to read the owner’s data) 58、android.permission.READ_SMS 允許程式讀取簡訊息(Allows an application to read SMS messages.) 59、android.permission.READ_SYNC_SETTINGS 允許程式讀取同步設定(Allows applications to read the sync settings) 60、android.permission.READ_SYNC_STATS 允許程式讀取同步狀態(Allows applications to read the sync stats) 61、android.permission.REBOOT 請求能夠重新啟動裝置(Required to be able to reboot the device. ) 62、android.permission.RECEIVE_BOOT_COMPLETED 允許一個程式接收到 ACTION_BOOT_COMPLETED廣播在系統完成啟動(Allows an application to receive the ACTION_BOOT_COMPLETED that is broadcast after the system finishes booting. ) 63、android.permission.RECEIVE_MMS 允許一個程式監控將收到MMS彩信,記錄或處理(Allows an application to monitor incoming MMS messages, to record or perform processing on them. ) 64、android.permission.RECEIVE_SMS 允許程式監控一個將收到簡訊息,記錄或處理(Allows an application to monitor incoming SMS messages, to record or perform processing on them.) 65、android.permission.RECEIVE_WAP_PUSH 允許程式監控將收到WAP PUSH資訊(Allows an application to monitor incoming WAP push messages. ) 66、android.permission.RECORD_AUDIO 允許程序錄制音訊(Allows an application to record audio) 67、android.permission.REORDER_TASKS 允許程式改變Z軸排列任務(Allows an application to change the Z-order of tasks) 68、android.permission.RESTART_PACKAGES 允許程式重新啟動其他程式(Allows an application to restart other applications) 69、android.permission.SEND_SMS 允許程式傳送SMS簡訊(Allows an application to send SMS messages) 70、android.permission.SET_ACTIVITY_WATCHER 允許程式監控或控制activities已經啟動全域性系統中Allows an application to watch and control how activities are started globally in the system. 71、android.permission.SET_ALWAYS_FINISH 允許程式控制是否活動間接完成在處於後臺時Allows an application to control whether activities are immediately finished when put in the background. 72、android.permission.SET_ANIMATION_SCALE 修改全域性資訊比例(Modify the global animation scaling factor.) 73、android.permission.SET_DEBUG_APP 配置一個程式用於除錯(Configure an application for debugging.) 74、android.permission.SET_ORIENTATION 允許底層訪問設定螢幕方向和實際旋轉(Allows low-level access to setting the orientation (actually rotation) of the screen.) 75、android.permission.SET_PREFERRED_APPLICATIONS 允許一個程式修改列表引數 PackageManager.addPackageToPreferred() 和PackageManager.removePackageFromPreferred()方法(Allows an application to modify the list of preferred applications with the PackageManager.addPackageToPreferred() and PackageManager.removePackageFromPreferred() methods.) 76、android.permission.SET_PROCESS_FOREGROUND 允許程式當前執行程式強行到前臺(Allows an application to force any currently running process to be in the foreground.) 77、android.permission.SET_PROCESS_LIMIT 允許設定最大的執行程序數量(Allows an application to set the maximum number of (not needed) application processes that can be running. ) 78、android.permission.SET_TIME_ZONE 允許程式設定時間區域(Allows applications to set the system time zone) 79、android.permission.SET_WALLPAPER 允許程式設定桌布(Allows applications to set the wallpaper ) 80、android.permission.SET_WALLPAPER_HINTS 允許程式設定桌布hits(Allows applications to set the wallpaper hints) 81、android.permission.SIGNAL_PERSISTENT_PROCESSES 允許程式請求傳送訊號到所有顯示的程序中 (Allow an application to request that a signal be sent to all persistent processes) 82、android.permission.STATUS_BAR 允許程式開啟、關閉或禁用狀態列及圖示Allows an application to open, close, or disable the status bar and its icons. 83、android.permission.SUBSCRIBED_FEEDS_READ 允許一個程式訪問訂閱RSS Feed內容提供(Allows an application to allow access the subscribed feeds ContentProvider. ) 84、android.permission.SUBSCRIBED_FEEDS_WRITE 系統暫時保留改設定,android開發網認為未來版本會加入該功能。 85、android.permission.SYSTEM_ALERT_WINDOW 允許一個程式開啟視窗使用 TYPE_SYSTEM_ALERT,顯示在其他所有程式的頂層(Allows an application to open windows using the type TYPE_SYSTEM_ALERT, shown on top of all other applications. ) 86、android.permission.VIBRATE 允許訪問振動裝置(Allows access to the vibrator) 87、android.permission.WAKE_LOCK 允許使用PowerManager的 WakeLocks保持程序在休眠時從螢幕消失( Allows using PowerManager WakeLocks to keep processor from sleeping or screen from dimming) 88、android.permission.WRITE_APN_SETTINGS 允許程式寫入API設定(Allows applications to write the apn settings) 89、android.permission.WRITE_CALENDAR 允許一個程式寫入但不讀取使用者日曆資料(Allows an application to write (but not read) the user’s calendar data. ) 90、android.permission.WRITE_CONTACTS 允許程式寫入但不讀取使用者聯絡人資料(Allows an application to write (but not read) the user’s contacts data. ) 91、android.permission.WRITE_GSERVICES 允許程式修改Google服務地圖(Allows an application to modify the Google service map. ) 92、android.permission.WRITE_OWNER_DATA 允許一個程式寫入但不讀取所有者資料(Allows an application to write (but not read) the owner’s data.) 93、android.permission.WRITE_SETTINGS 允許程式讀取或寫入系統設定(Allows an application to read or write the system settings. ) 94、android.permission.WRITE_SMS 允許程式寫簡訊(Allows an application to write SMS messages) 95、android.permission.WRITE_SYNC_SETTINGS 允許程式寫入同步設定(Allows applications to write the sync settings)