Android 6.0以上主动申请权限

在开发过程中,发现安卓系统申请读写权限无效,调查发现安卓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/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

发表回复

登录后才能评论
免费咨询
免费咨询
扫码关注
扫码关注
联系站长

站长Johngo!

大数据和算法重度研究者!

持续产出大数据、算法、LeetCode干货,以及业界好资源!

2022012703491714

微信来撩,免费咨询:xiaozhu_tec

分享本页
返回顶部