本文整理汇总了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;
}
示例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);
}
}
示例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();
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
}
示例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;
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
}
示例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
)
);
}
}
示例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);
}
示例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");
}
}