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. Android中的四种启动方式
  2. android的Support Library
  3. Android(安卓)定时器大全
  4. Android(安卓)studio 下拉刷新,加载更多使
  5. Android的底部菜单
  6. Android的图片压缩类ThumbnailUtils
  7. Android——动画专题研究
  8. Android(安卓)关于WebView加载完成的多种
  9. android push机制-C2DM
  10. android 4种存储方式