Android权限的前世今生

一:初解


permission,用来描述拥有做某件事的权利。

Android系统中权限分为:


普通级别(Normal)

ACCESS_LOCATION_EXTRA_COMMANDSACCESS_NETWORK_STATE

ACCESS_NOTIFICATION_POLICY

ACCESS_WIFI_STATE

BLUETOOTH

BLUETOOTH_ADMIN

BROADCAST_STICKY

CHANGE_NETWORK_STATE

CHANGE_WIFI_MULTICAST_STATE

CHANGE_WIFI_STATE

DISABLE_KEYGUARD

EXPAND_STATUS_BAR

GET_PACKAGE_SIZE

INSTALL_SHORTCUT

INTERNET

KILL_BACKGROUND_PROCESSES

MODIFY_AUDIO_SETTINGS

NFC

READ_SYNC_SETTINGS

READ_SYNC_STATS

RECEIVE_BOOT_COMPLETED

REORDER_TASKS

REQUEST_INSTALL_PACKAGES

SET_ALARM

SET_TIME_ZONE

SET_WALLPAPER

SET_WALLPAPER_HINTS

TRANSMIT_IR

UNINSTALL_SHORTCUT

USE_FINGERPRINT

VIBRATE

WAKE_LOCK

WRITE_SYNC_SETTINGS

危险级别(dangerous)

group:android.permission-group.CONTACTS

permission:android.permission.WRITE_CONTACTS

permission:android.permission.GET_ACCOUNTS

permission:android.permission.READ_CONTACTS

group:android.permission-group.PHONE

permission:android.permission.READ_CALL_LOG

permission:android.permission.READ_PHONE_STATE

permission:android.permission.CALL_PHONE

permission:android.permission.WRITE_CALL_LOG

permission:android.permission.USE_SIP

permission:android.permission.PROCESS_OUTGOING_CALLS

permission:com.android.voicemail.permission.ADD_VOICEMAIL

group:android.permission-group.CALENDAR

permission:android.permission.READ_CALENDAR

permission:android.permission.WRITE_CALENDAR

group:android.permission-group.CAMERA

permission:android.permission.CAMERA

group:android.permission-group.SENSORS

permission:android.permission.BODY_SENSORS

group:android.permission-group.LOCATION

permission:android.permission.ACCESS_FINE_LOCATION

permission:android.permission.ACCESS_COARSE_LOCATION

group:android.permission-group.STORAGE

permission:android.permission.READ_EXTERNAL_STORAGE

permission:android.permission.WRITE_EXTERNAL_STORAGE

group:android.permission-group.MICROPHONE

permission:android.permission.RECORD_AUDIO

group:android.permission-group.SMS

permission:android.permission.READ_SMS

permission:android.permission.RECEIVE_WAP_PUSH

permission:android.permission.RECEIVE_MMS

permission:android.permission.RECEIVE_SMS

permission:android.permission.SEND_SMS

permission:android.permission.READ_CELL_BROADCASTS

签名级别(signature)

系统/签名级别(signature or system)


二:Android 6.0权限机制

新的权限机制更好的保护了用户的隐私,Google将权限分为两类,一类是Normal Permissions,这类权限一般不涉及用户隐私,是不需要用户进行授权的,比如手机震动、访问网络等;另一类是Dangerous Permission,一般是涉及到用户隐私的,需要用户进行授权,比如读取sdcard、访问通讯录等。

三:DEMO

/**

*下面练习动态权限申请

*/

public voidcall(View v) {

if(ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE)

!= PackageManager.PERMISSION_GRANTED) {

if(ActivityCompat.shouldShowRequestPermissionRationale(this,

Manifest.permission.CALL_PHONE)) {

Toast.makeText(this,"需要拨打权限", Toast.LENGTH_SHORT).show();

}

//如果没有授权,则去申请

ActivityCompat.requestPermissions(this,newString[]{Manifest.permission.CALL_PHONE},

MY_PERMISSIONS_REQUEST_CALL_PHONE);

}else{

callPhone();

}

}

private voidcallPhone() {

Intent intent =newIntent(Intent.ACTION_CALL);

Uri data = Uri.parse("tel:"+"10086");

intent.setData(data);

startActivity(intent);

}

@Override

public voidonRequestPermissionsResult(intrequestCode, String[] permissions,int[] grantResults) {

if(requestCode ==MY_PERMISSIONS_REQUEST_CALL_PHONE) {

if(grantResults[0] == PackageManager.PERMISSION_GRANTED) {

callPhone();

}else{

Toast.makeText(this,"需要拨打权限", Toast.LENGTH_SHORT).show();

}

}

super.onRequestPermissionsResult(requestCode, permissions, grantResults);

}

你可能感兴趣的:(Android权限的前世今生)