当前位置: 首页>>代码示例>>Java>>正文


Java PermissionChecker类代码示例

本文整理汇总了Java中android.support.v4.content.PermissionChecker的典型用法代码示例。如果您正苦于以下问题:Java PermissionChecker类的具体用法?Java PermissionChecker怎么用?Java PermissionChecker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PermissionChecker类属于android.support.v4.content包,在下文中一共展示了PermissionChecker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkPermission

import android.support.v4.content.PermissionChecker; //导入依赖的package包/类
public boolean checkPermission(Context context, String... permission) {

        boolean nr = true;

        for (int i = 0; i < permission.length; i++) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                // targetSdkVersion >= Android M, we can
                // use Context#checkSelfPermission
                nr = context.checkSelfPermission(permission[i])
                        == PackageManager.PERMISSION_GRANTED;
            } else {
                // targetSdkVersion < Android M, we have to use PermissionChecker
                nr = PermissionChecker.checkSelfPermission(context, permission[i])
                        == PermissionChecker.PERMISSION_GRANTED;
            }

            if (!nr) {
                break;
            }
        }
        return nr;
    }
 
开发者ID:DuanJiaNing,项目名称:Musicoco,代码行数:23,代码来源:PermissionManager.java

示例2: startCameraActivity

import android.support.v4.content.PermissionChecker; //导入依赖的package包/类
protected void startCameraActivity() {
    int permissionCheck = PermissionChecker.checkCallingOrSelfPermission(this,
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
    if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
        Intent photoPickerIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                getOutputMediaFile());
        photoPickerIntent.putExtra("outputFormat",
                Bitmap.CompressFormat.JPEG.toString());
        startActivityForResult(
                Intent.createChooser(photoPickerIntent, getString(R.string.upload_picker_title)),
                CAMERA_CODE);
    } else {
        showMenu(1);
    }
}
 
开发者ID:eventtus,项目名称:photo-editor-android,代码行数:17,代码来源:BaseActivity.java

示例3: onRequestPermissionsResult

import android.support.v4.content.PermissionChecker; //导入依赖的package包/类
void onRequestPermissionsResult(String permissions[], int[] grantResults, boolean[] shouldShowRequestPermissionRationale) {
    for (int i = 0, size = permissions.length; i < size; i++) {
        log("onRequestPermissionsResult  " + permissions[i]);
        // Find the corresponding subject
        PublishSubject<Permission> subject = mSubjects.get(permissions[i]);
        if (subject == null) {
            // No subject found
            Log.e(RxPermissions.TAG, "RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.");
            return;
        }
        mSubjects.remove(permissions[i]);
        boolean granted = (grantResults[i] == PackageManager.PERMISSION_GRANTED) && (PermissionChecker.checkSelfPermission(getContext(), permissions[i]) == PermissionChecker.PERMISSION_GRANTED);
        subject.onNext(new Permission(permissions[i], granted, shouldShowRequestPermissionRationale[i]));
        subject.onComplete();
    }
}
 
开发者ID:CodyyAndroid,项目名称:RxPermissions,代码行数:17,代码来源:RxPermissionsFragment.java

示例4: checkTelephonyPermissions

import android.support.v4.content.PermissionChecker; //导入依赖的package包/类
@Override
public void checkTelephonyPermissions() {
    if(!mRequestPermissions.isEmpty()) {
        if(ContextCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_SMS)
                != PermissionChecker.PERMISSION_GRANTED ||
                (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
                        != PermissionChecker.PERMISSION_GRANTED)) {
            mRequestingPermission = mRequestPermissions.get(0);
            mRequestPermissions.remove(0);
            PopUp.show((mRequestingPermission == EventCategories.IPC_BLE_NOTIFICATION_INCOMING_CALL)
                            ? getString(R.string.telephony_permission)
                            : getString(R.string.sms_permission),
                    getString(R.string.permissions_needed_title),
                    R.drawable.message_face, R.drawable.blue_btn, PopUp.GIFF_ANIMATION_NONE,
                    PopUp.TYPE_CHOICE,
                    notificationOKHandler,
                    notificationCancelHandler);
        }
    }
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:21,代码来源:ProjectActivity.java

示例5: checkTelephonyPermissions

import android.support.v4.content.PermissionChecker; //导入依赖的package包/类
@Override
public void checkTelephonyPermissions() {
    if(!requestPermissions.isEmpty()) {
        if(ContextCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_SMS) != PermissionChecker.PERMISSION_GRANTED ||
                (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PermissionChecker.PERMISSION_GRANTED)) {
            requestingPermission = requestPermissions.get(0);
            requestPermissions.remove(0);
            PopUp.show((requestingPermission == EventCategories.IPC_BLE_NOTIFICATION_INCOMING_CALL) ? getString(R.string
                            .telephony_permission) : getString(R.string.sms_permission),
                    getString(R.string.permissions_needed_title),
                    R.drawable.message_face, R.drawable.blue_btn, PopUp.GIFF_ANIMATION_NONE,
                    PopUp.TYPE_CHOICE,
                    notificationOKHandler,
                    notificationCancelHandler);
        }
    }
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:18,代码来源:PairingActivity.java

示例6: applyPermission

import android.support.v4.content.PermissionChecker; //导入依赖的package包/类
/**
 * 请求权限
 */
public void applyPermission(String[] permissions, onRequestPermissionsListener listener) {
    this.listener = listener;
    List<String> permissionList = new ArrayList<>();
    for (String permission:permissions ) {
        if(ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PermissionChecker.PERMISSION_GRANTED){
            permissionList.add(permission);
        }
    }
    if(permissionList.isEmpty()){
       listener.onSuccess();
    }else{
        ActivityCompat.requestPermissions(this,permissionList.toArray(new String[permissionList.size()]), WRITE_EXTERNAL_STORAGE);
    }

}
 
开发者ID:Vicent9920,项目名称:FanChat,代码行数:19,代码来源:BaseActivity.java

示例7: onRequestPermissionsResult

import android.support.v4.content.PermissionChecker; //导入依赖的package包/类
/**
 * 申请权限回调
 */
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    List<String> defeatedValue = new ArrayList<>();
    switch (requestCode) {
        case WRITE_EXTERNAL_STORAGE:
            for (int i = 0; i < grantResults.length; i++) {
                String value = permissions[i];
                if(grantResults[i] != PermissionChecker.PERMISSION_GRANTED){
                    defeatedValue.add(value);
                }
            }
            if(defeatedValue.isEmpty()){
                listener.onSuccess();
            }else{
                listener.onDefeated(defeatedValue);
            }
            break;
    }
}
 
开发者ID:Vicent9920,项目名称:FanChat,代码行数:23,代码来源:BaseActivity.java

示例8: checkPermission

import android.support.v4.content.PermissionChecker; //导入依赖的package包/类
/**
 * 请求单个权限
 *
 * @param activity   Activity
 * @param permission 权限
 * @param rationale  提示
 */
public void checkPermission(final Activity activity, final String permission, String rationale) {
    if (PermissionChecker.checkSelfPermission(activity, permission) != PackageManager.PERMISSION_GRANTED) {
        mActivity = activity;
        if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
            BaseDialog.create(activity)
                    .setTitle(DESC_TITLE)
                    .setContent(rationale)
                    .setPositive(new BaseDialog.OnClickListener() {
                        @Override
                        public void onClick(BaseDialog dialog) {
                            ActivityCompat.requestPermissions(mActivity, new String[]{permission}, REQUEST_CODE);
                        }
                    })
                    .show();
        } else {
            ActivityCompat.requestPermissions(activity, new String[]{permission}, REQUEST_CODE);
        }
    } else {
        if (mOnGrantedListener != null) mOnGrantedListener.onGranted();
    }
}
 
开发者ID:DongYuHui,项目名称:android_daily_record,代码行数:29,代码来源:PermissionUtil.java

示例9: hasSelfPermissions

import android.support.v4.content.PermissionChecker; //导入依赖的package包/类
/**
 * Returns true if <code>Activity</code> or <code>Fragment</code> has access to all given permissions.
 *
 * @param context     context
 * @param permissions permissions
 * @return returns true if <code>Activity</code> or <code>Fragment</code> has access to all given permissions.
 */
@TargetApi(value = Build.VERSION_CODES.M)
public static boolean hasSelfPermissions(Context context, String... permissions) {
    if (permissions == null || permissions.length == 0) {
        return false;
    }

    for (String permission : permissions) {
        if (permission.equals(Manifest.permission.SYSTEM_ALERT_WINDOW)) {
            if (!canDrawOverlays(context)) {
                return false;
            }
        } else if (permission.equals(Manifest.permission.WRITE_SETTINGS)) {
            if (!canWriteSetting(context)) {
                return false;
            }
        } else if (PermissionChecker.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
    }
    return true;
}
 
开发者ID:HujiangTechnology,项目名称:android_library_permissiondispatcher,代码行数:29,代码来源:PermissionUtils.java

示例10: findDeniedPermissions

import android.support.v4.content.PermissionChecker; //导入依赖的package包/类
public static List<String> findDeniedPermissions(Activity activity, String... permission) {
    List<String> denyPermissions = new ArrayList<>();
    if (!isOverMarshmallow()) {
        return denyPermissions;
    }

    for (String value : permission) {
        if (value.equals(Manifest.permission.SYSTEM_ALERT_WINDOW)) {
            if(!canDrawOverlays(activity)) {
                denyPermissions.add(value);
            }
        } else if(value.equals(Manifest.permission.WRITE_SETTINGS)) {
            if(!canWriteSetting(activity)) {
                denyPermissions.add(value);
            }
        } else if(PermissionChecker.checkSelfPermission(activity, value) != PackageManager.PERMISSION_GRANTED) {
            denyPermissions.add(value);
        }
    }
    return denyPermissions;
}
 
开发者ID:HujiangTechnology,项目名称:android_library_permissiondispatcher,代码行数:22,代码来源:PermissionUtils.java

示例11: onClick

import android.support.v4.content.PermissionChecker; //导入依赖的package包/类
@Override
public void onClick(View view) {

    mLastSelectedButtonId = view.getId();

    if (R.id.radioExternalShare == mRadioGroup.getCheckedRadioButtonId()) {

        if (PackageManager.PERMISSION_GRANTED != PermissionChecker.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

            // パーミッション許可ない場合はRuntimePermissionを要求して処理終了
            ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_RUNTIME_PERMISSION);
            return;
        }
    }

    // 読み書き実行
    readOrWrite();
}
 
开发者ID:yokmama,项目名称:honki_android2,代码行数:19,代码来源:MainActivity.java

示例12: onRequestPermissionsResult

import android.support.v4.content.PermissionChecker; //导入依赖的package包/类
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
        case REQUEST_CAMERA:
            for (int i = 0; i < permissions.length; i++) {
                if (grantResults[i] == PermissionChecker.PERMISSION_DENIED) {
                    String reason = permissions[i] + " is denied !";
                    T.showLToast(mContext, reason);
                    return;
                }
            }
            openCamera();
            break;
        default:
            break;
    }
}
 
开发者ID:REBOOTERS,项目名称:AndroidAnimationExercise,代码行数:19,代码来源:CameraActivity.java

示例13: onRequestPermissionsResult

import android.support.v4.content.PermissionChecker; //导入依赖的package包/类
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (grantResults[0] == PermissionChecker.PERMISSION_GRANTED){
        subscription.add(
                getLocation().subscribe(
                        it -> {
                            model.setLocation(new GeoLocation(it.getLatitude(), it.getLongitude()));
                            locationText.setVisibility(View.VISIBLE);
                            locationText.setText(getString(R.string.lat_and_lon, it.getLatitude(), it.getLongitude()));
                        },
                        Throwable::printStackTrace
                )
        );
    }
}
 
开发者ID:moko256,项目名称:twicalico,代码行数:17,代码来源:PostActivity.java

示例14: checkSelfPermission

import android.support.v4.content.PermissionChecker; //导入依赖的package包/类
/**
 * 检查权限授权状态
 *
 * @param context
 * @param permission
 * @return
 */
int checkSelfPermission(Context context, String permission) {
    try {
        final PackageInfo info = context.getPackageManager().getPackageInfo(
                context.getPackageName(), 0);
        int targetSdkVersion = info.applicationInfo.targetSdkVersion;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (targetSdkVersion >= Build.VERSION_CODES.M) {
                Log.i(TAG, "targetSdkVersion >= Build.VERSION_CODES.M");
                return ContextCompat.checkSelfPermission(context, permission);
            } else {
                return PermissionChecker.checkSelfPermission(context, permission);
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return ContextCompat.checkSelfPermission(context, permission);
}
 
开发者ID:smuyyh,项目名称:SprintNBA,代码行数:26,代码来源:AcpService.java

示例15: allowPermission

import android.support.v4.content.PermissionChecker; //导入依赖的package包/类
/**
 * Gives the specified permission to this app, if it is not granted
 *
 * @param activity       the activity for accessing resources
 * @param permissionName the permission name to check
 * @see android.Manifest.permission
 */
public static void allowPermission(Activity activity, String permissionName) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return;
    }

    // if permission is still not granted
    if (PermissionChecker.checkSelfPermission(activity, permissionName) != PermissionChecker.PERMISSION_GRANTED) {
        // try get access for permission
        ActivityCompat.requestPermissions(activity,
                new String[]{
                        permissionName
                }, PERMISSION_GRANTED_CODE);
    } else {
        Log.i(TAG, "Permission " + permissionName + " is granted");
    }
}
 
开发者ID:EuphoriaDev,项目名称:euphoria-vk-client,代码行数:24,代码来源:PermissionAllower.java


注:本文中的android.support.v4.content.PermissionChecker类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。