Android 6.0 system Get Permissions

Source: Internet
Author: User

Prior to the release of Android 6.0 (API 23), all permissions are displayed to the user when the app is installed, and the user chooses to install to accept all of these permissions and cannot revoke authorization for those permissions. But starting with Android 6.0, some of the more dangerous permissions need to be explicitly framed when the program runs, requesting user authorization. Therefore, when the application was developed, the corresponding permissions were configured in the manifest file, which did not achieve the previous effect. So, what do we do now? Two ideas are available for reference only:

1: Determine the version of the Android system, if not 6.0 and above, according to normal logic processing, if it is, then go to open the System box, request system permissions.

2: Directly determine whether the current application has the corresponding permissions, if any, processing the logic code, if not then go to request system permissions.

Individuals tend to prefer the second, but the second must be configured in the manifest file, for example, if you need camera permissions, you can also configure the camera's permissions in manifest by the previous development app. Next, how do you implement the second type:

Check that the system has the appropriate permissions before you perform the action that requires permissions, taking camera permissions as an example:

if (packagemanager.permission_granted = = Contextcompat.checkselfpermission (Newgoodsactivity.this, Manifest.permission.CAMERA)) {

/**

* On behalf of the app already has this permission, to do function processing

**/

}else{

/**

* On behalf of the app has not yet obtained this permission to apply for permission

**/ }

So if the app doesn't have permissions, how to get it? That is, Android 6.0 and later, how to call the system frame, let the user operation corresponding permissions? The method is requestpermissions, the usage is similar to the Startacitivityforresult method, or take the camera operation as an example:

Request Permission:

String[] perms = {"Android.permission.CAMERA"};

int permsrequestcode = 890;

Requestpermissions (perms, Permsrequestcode);

The callback method after the user operation is:

@Override

public void Onrequestpermissionsresult (int permsrequestcode, string[] permissions, int[] grantresults) {

Switch (permsrequestcode) {

Case 890:

Boolean cameraaccepted = grantresults[0]== packagemanager.permission_granted;

if (cameraaccepted) {

After the authorization is successful, call the system camera to take a photo operation, etc.

}else{

After the user authorizes the refusal, the friendly hint will be able

}

Break

}

}


The first way of thinking is the same as the second, which is the Requestpermissions method.

Reference: http://mp.weixin.qq.com/s?__biz=MjM5NDkxMTgyNw==&mid=2653057440&idx=1&sn= 0dec446942b2531edfc6210eb6302228&scene=0#wechat_redirect


This article from "Mo Panic, raise straight forward" blog, please be sure to keep this source http://kunyali.blog.51cto.com/4890065/1828165

Android 6.0 system Get Permissions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.