Esempio n. 1
0
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   /*
       从Settings界面跳转回来,标准代码,就这么写
   */
   if (requestCode == EasyPermission.SETTINGS_REQ_CODE) {
     if (EasyPermission.hasPermissions(mContext, mPermissions)) {
       // 已授权,处理业务逻辑
       onEasyPermissionGranted(mRequestCode, mPermissions);
     } else {
       onEasyPermissionDenied(mRequestCode, mPermissions);
     }
   }
 }
Esempio n. 2
0
  // rationale: 申请授权理由
  protected void requestPermission(
      int requestCode,
      String[] permissions,
      String rationale,
      PermissionCallBack permissionCallback) {
    this.mRequestCode = requestCode;
    this.mPermissionCallBack = permissionCallback;
    this.mPermissions = permissions;

    EasyPermission.with(this)
        .addRequestCode(requestCode)
        .permissions(permissions)
        // .nagativeButtonText(android.R.string.ok)
        // .positveButtonText(android.R.string.cancel)
        .rationale(rationale)
        .request();
  }
Esempio n. 3
0
  @Override
  public void onEasyPermissionDenied(final int requestCode, final String... perms) {
    // rationale: Never Ask Again后的提示信息
    if (EasyPermission.checkDeniedPermissionsNeverAskAgain(
        this,
        "授权啊,不授权没法用啊," + "去设置里授权大哥",
        android.R.string.ok,
        android.R.string.cancel,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            if (mPermissionCallBack != null) {
              mPermissionCallBack.onPermissionDeniedM(requestCode, perms);
            }
          }
        },
        perms)) {
      return;
    }

    if (mPermissionCallBack != null) {
      mPermissionCallBack.onPermissionDeniedM(requestCode, perms);
    }
  }
Esempio n. 4
0
 @Override
 public void onRequestPermissionsResult(
     int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
   super.onRequestPermissionsResult(requestCode, permissions, grantResults);
   EasyPermission.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
 }