6.0之前是install time permissions model,6.0之后取是runtime permissions model。
后者在安装的时候会跟用户显示所需要的权限,并在app运行的时候去申请权限。
Android将系统权限分成了四个保护等级normal,dangerous,signature,signatureOrSystem。
最常见的是normal permission和dangerous permission两类。
Normal permission:这类权限可以在app安装期间被默认赋予
android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_NOTIFICATION_POLICY
android.permission.ACCESS_WIFI_STATE
android.permission.ACCESS_WIMAX_STATE
android.permission.BLUETOOTH
android.permission.BLUETOOTH_ADMIN
android.permission.BROADCAST_STICKY
android.permission.CHANGE_NETWORK_STATE
android.permission.CHANGE_WIFI_MULTICAST_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.CHANGE_WIMAX_STATE
android.permission.DISABLE_KEYGUARD
android.permission.EXPAND_STATUS_BAR
android.permission.FLASHLIGHT
android.permission.GET_ACCOUNTS
android.permission.GET_PACKAGE_SIZE
android.permission.INTERNET
android.permission.KILL_BACKGROUND_PROCESSES
android.permission.MODIFY_AUDIO_SETTINGS
android.permission.NFC
android.permission.READ_SYNC_SETTINGS
android.permission.READ_SYNC_STATS
android.permission.RECEIVE_BOOT_COMPLETED
android.permission.REORDER_TASKS
android.permission.REQUEST_INSTALL_PACKAGES
android.permission.SET_TIME_ZONE
android.permission.SET_WALLPAPER
android.permission.SET_WALLPAPER_HINTS
android.permission.SUBSCRIBED_FEEDS_READ
android.permission.TRANSMIT_IR
android.permission.USE_FINGERPRINT
android.permission.VIBRATE
android.permission.WAKE_LOCK
android.permission.WRITE_SYNC_SETTINGS
com.android.alarm.permission.SET_ALARM
com.android.launcher.permission.INSTALL_SHORTCUT
com.android.launcher.permission.UNINSTALL_SHORTCUT
dangerous permission:这类权限必须在运行的时候申请
CALENDAR:READ_CALENDAR;WRITE_CALENDAR
CAMERA:CAMERA
CONTACTS:READ_CONTACTS;WRITE_CONTACTS;GET_ACCOUNTS
LOCATION:ACCESS_FINE_LOCATION;ACCESS_COARSE_LOCATION
MICROPHONE:RECORD_AUDIO
PHONE:READ_PHONE_STATE;CALL_PHONE;READ_CALL_LOG;WRITE_CALL_LOG;ADD_VOICEMAIL;USE_SIP;PROCESS_OUTGOING_CALLS
SENSORS:BODY_SENSORS
SMS:SEND_SMS;RECEIVE_SMS;READ_SMS;RECEIVE_WAP_PUSH;RECEIVE_MMS
STORAGE:READ_EXTERNAL_STORAGE;WRITE_EXTERNAL_STORAGE
API23检查和请求权限的方法是:checkSelfPermission和requestPermissions(API23)
流程是:先检查有没有权限,如果有直接调用,如果没有,则请求权限,接下来
论用户同意还是拒绝,activity的onRequestPermissionsResult会被回调来通知结果(通过第三个参数)。
如果用户第一次拒绝权限,下次requestPermissions的时候使用shouldShowRequestPermissionRationale来跟用户解释。
权限的第三方框架:https://github.com/hotchemi/PermissionsDispatcher
参考:
android 6.0权限:http://www.cnblogs.com/zqlxtt/p/4873831.html
泡网上的解释:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0830/3387.html
时间: 2024-11-08 14:22:04