Coder Social home page Coder Social logo

xpermission's Introduction

XPermission 最快最简单的方式适配Android6.0权限

使用方法:继承XPermissActivity,调用requestPermission()获取权限

  requestPermission(new String[]{Manifest.permission.CAMERA}, new PermissionHandler() {
      @Override
      public void onGranted() {
          Intent intent = new Intent(); //调用照相机
          intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
          startActivity(intent);
      }

      @Override
      public void onDenied() {
          Toast.makeText(MainActivity.this, "拒绝", Toast.LENGTH_SHORT).show();
      }

  });


  requestPermission(new String[]{Manifest.permission.CALL_PHONE}, new PermissionHandler() {
        @Override
        public void onGranted() {
            Intent intent = new Intent(Intent.ACTION_CALL);
            Uri data = Uri.parse("tel:10086");
            intent.setData(data);
            startActivity(intent);
        }

        @Override
        public boolean onNeverAsk() {
            new AlertDialog.Builder(MainActivity.this)
                    .setTitle("权限申请")
                    .setMessage("在设置-应用-权限中开始电话权限,以保证功能的正常使用")
                    .setPositiveButton("去开启", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            Uri uri = Uri.fromParts("package", getPackageName(), null);
                            intent.setData(uri);
                            startActivity(intent);

                            dialog.dismiss();
                        }
                    })
                    .setNegativeButton("取消", null)
                    .setCancelable(false)
                    .show();

            return true;
        }
  });

xpermission's People

Contributors

a5533348 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.