Either check for target >=23 or simply add below line above your method

@TargetApi(Build.VERSION_CODES.M)

For example, If you are checking for storage permissions, then you can refer to this function,

@TargetApi(Build.VERSION_CODES.M)    public boolean CheckStoragePermission() {        int permissionCheckRead = ContextCompat.checkSelfPermission(context,                Manifest.permission.READ_EXTERNAL_STORAGE);        if (permissionCheckRead != PackageManager.PERMISSION_GRANTED) {            if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) context,                    Manifest.permission.READ_EXTERNAL_STORAGE)) {                // Show an expanation to the user *asynchronously* -- don't block                // this thread waiting for the user's response! After the user                // sees the explanation, try again to request the permission.                ActivityCompat.requestPermissions((Activity) context,                        new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},                        Define.PERMISSION_STORAGE);            } else {                // No explanation needed, we can request the permission.                ActivityCompat.requestPermissions((Activity) context,                        new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},                        Define.PERMISSION_STORAGE);                // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an                // app-defined int constant. The callback method gets the                // result of the request.            }            return false;        } else            return true;    }

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Mysql无法选取非聚合列的解决方法
  2. mysql的定时任务实例教程
  3. MySQL分页Limit的优化过程实战
  4. mysql增量备份及断点恢复脚本实例
  5. 在golang中操作mysql数据库的实现代码
  6. centos7.4系统中yum源安装mysql 5.6
  7. Navicat修改MySQL数据库密码的多种方法
  8. 详解 Mysql中的delimiter定义及作用
  9. mysql server 8.0.3安装配置方法图文教程
  10. mysql 8.0.12 winx64下载安装教程