Android6.0 above apply for permission to manage user privileges lead to denial flash back quickly once and for all solutions

Problem:
Android development, rights are an important part of the inevitable link. Especially newly recruited white who believe in the authority table to join in with AndroidManifest everything will be fine. Or normal thought their own testing, packaging, publishing all kinds of things come BUG or flash back after the installation of others. By commissioning could not find where the problem lies. I did not expect that, did not get permission to lead to the calling system function fails, flash back or law cited other problems. In just in project development encountered this problem, try to take on a variety of mobile phones, mobile phone flash back, through the commissioning discovered the problem. I believe in your development will also encounter this problem, this problem comes from the android system upgrade to a later version of the phone android 6, there will be such a problem.

Here Insert Picture Description
analysis:

Through the analysis, when the phone is installed, a number of manufacturers led to the system is disabled by default privilege user permissions are disabled, 2 habitual user to install the application active disabled rights, disabled rights unintentionally click function 3-user installation. After the user actively disable permissions, can not eject when initiating the request interface to request permission, permission to unscrupulous use.

Solution:

Verify that their rights are disabled

The requesting user permission to open

Direct the user to open the system settings interface permissions

Use the system function
ActivityCompat.checkSelfPermission
ActivityCompat.shouldShowRequestPermissionRationale
ActivityCompat.requestPermissions

Are the root right is turned on
whether the user actively disable the
user to assign permissions requests

Resolution process:

Here Insert Picture Description

Resolution process

There are programs to understand, you can write code

Write one application for permission, it would be too much trouble, I do not think we want to engage in technology, and we want is fast, there is no "once and for all" approach, the answer is yes. The problem can be solved by two lines of code, this is a much simpler it?

PermissionUtil.checkPermission(this,null); PermissionUtil.onRequestPermissionsResult(this,requestCode,permissions,grantResults);

Sample code:

/**

* 启动ACtivity 权限申请

*/

public class SplashActivity extends AppCompatActivity {

@Override

protected void onCreate(@Nullable Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_splash);
//第一步
//测试权限并请求权限

PermissionUtil.checkPermission(this,null);

}

@Override

public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {

//第二步

//申请权限结果用户禁用引到系统设置

PermissionUtil.onRequestPermissionsResult(this,requestCode,permissions,grantResults);

}

}

Core code of all package code written PermissionUtil class completed, using the main code remains simple.
Simple enough, right only two lines of code, each new project can be quickly transplanted.

Display the most core code, I believe your wisdom to other simple code difficult to see you now!

Here Insert Picture Description
Core code

Restrictions configured by the AndroidManifest.xml, the efficacy eleven, one need to manually written code for verification so much trouble. If you do not have permission to apply for permission to call, if a user actively refused permission to jump directly to the settings interface.

Let's look at the test results of our development projects
Here Insert Picture Description

Run the application permissions are disabled

Here Insert Picture DescriptionPop up when you start to apply the title

Here Insert Picture Description
Go to settings interface

When permissions are passed, it will not pop-up prompts
code already exist
https://download.csdn.net/download/gao5411/12117324

If necessary, please move on to the original code
or have any questions please give me a message

Released two original articles · won praise 1 · views 152

Guess you like

Origin blog.csdn.net/gao5411/article/details/104065784