在开发过程中,发现安卓系统申请读写权限无效,调查发现安卓6.0需要动态申请权限。
[En]
During the development, it was found that it was ineffective for the Android system to apply for read and write permission, and the survey found that Android 6. 0 needed to apply for permission dynamically.
在OnCreate里面加入下面代码
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, PERMISSIONS_STORAGE, REQUEST_PERMISSION_CODE);
}
}
所需的属性如下
[En]
The required attributes are as follows
private static final String[] PERMISSIONS_STORAGE = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
private static int REQUEST_PERMISSION_CODE = 1;
Original: https://www.cnblogs.com/c-x-a/p/16195361.html
Author: 公众号python学习开发
Title: Android 6.0以上主动申请权限
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/7348/
转载文章受原作者版权保护。转载请注明原作者出处!