本文整理汇总了Java中android.app.Activity.checkSelfPermission方法的典型用法代码示例。如果您正苦于以下问题:Java Activity.checkSelfPermission方法的具体用法?Java Activity.checkSelfPermission怎么用?Java Activity.checkSelfPermission使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.Activity
的用法示例。
在下文中一共展示了Activity.checkSelfPermission方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: askForPermissons
import android.app.Activity; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
private void askForPermissons() {
Activity activity = getParentActivity();
if (activity == null) {
return;
}
ArrayList<String> permissons = new ArrayList<>();
if (activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
permissons.add(Manifest.permission.READ_CONTACTS);
permissons.add(Manifest.permission.WRITE_CONTACTS);
permissons.add(Manifest.permission.GET_ACCOUNTS);
}
if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
permissons.add(Manifest.permission.READ_EXTERNAL_STORAGE);
permissons.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
String[] items = permissons.toArray(new String[permissons.size()]);
activity.requestPermissions(items, 1);
}
示例2: getPermission
import android.app.Activity; //导入方法依赖的package包/类
@TargetApi(M)
static private void getPermission(String[] permissions,Activity activity) {
if(Build.VERSION.SDK_INT>=23) {
ArrayList<String> preToDo = new ArrayList<>();
boolean tip = false;
for (String pre : permissions) {
if (activity.checkSelfPermission(pre) != PackageManager.PERMISSION_GRANTED) {
preToDo.add(pre);
if (activity.shouldShowRequestPermissionRationale(pre)) {
tip = true;
}
}
}
if (preToDo.size() == 0)
return;
if (tip)
showToast(sContext.getString(R.string.permissions_need));
activity.requestPermissions(preToDo.toArray(new String[preToDo.size()]), 0);
}
}
示例3: validatePermissions
import android.app.Activity; //导入方法依赖的package包/类
public static boolean validatePermissions(final Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
AlertDialog.Builder alert = new AlertDialog.Builder(activity);
alert.setTitle("Permission Error");
alert.setMessage("Grant permissions in the next dialog and retry download.");
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
}
});
alert.show();
return false;
}
} else {
return true;
}
}
示例4: isContactsPermissionGranted
import android.app.Activity; //导入方法依赖的package包/类
private static boolean isContactsPermissionGranted(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (activity.checkSelfPermission(READ_CONTACTS)
== PackageManager.PERMISSION_GRANTED) {
Timber.d("Permission is granted");
return true;
} else {
Timber.d("Permission is revoked");
ActivityCompat.requestPermissions(activity,
new String[]{READ_CONTACTS},
activity.getResources().getInteger(R.integer.contacts_request));
return false;
}
} else { //permission is automatically granted on sdk<23 upon installation
Timber.d("Permission is granted");
return true;
}
}
示例5: maybeRequestReadExternalStoragePermission
import android.app.Activity; //导入方法依赖的package包/类
/**
* Checks whether it's necessary to request the {@link permission#READ_EXTERNAL_STORAGE}
* permission read the specified {@link Uri}s, requesting the permission if necessary.
*
* @param activity The host activity for checking and requesting the permission.
* @param uris {@link Uri}s that may require {@link permission#READ_EXTERNAL_STORAGE} to read.
* @return Whether a permission request was made.
*/
@TargetApi(23)
public static boolean maybeRequestReadExternalStoragePermission(Activity activity, Uri... uris) {
if (Util.SDK_INT < 23) {
return false;
}
for (Uri uri : uris) {
if (Util.isLocalFileUri(uri)) {
if (activity.checkSelfPermission(permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
activity.requestPermissions(new String[] {permission.READ_EXTERNAL_STORAGE}, 0);
return true;
}
break;
}
}
return false;
}
示例6: isReadStoragePermissionGranted
import android.app.Activity; //导入方法依赖的package包/类
private static boolean isReadStoragePermissionGranted(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (activity.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
Timber.d("Permission is granted");
return true;
} else {
Timber.d("Permission is revoked");
ActivityCompat.requestPermissions(activity,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
activity.getResources().getInteger(R.integer.read_external_storage_request));
return false;
}
} else { //permission is automatically granted on sdk<23 upon installation
Timber.d("Permission is granted");
return true;
}
}
示例7: findPermissionResult
import android.app.Activity; //导入方法依赖的package包/类
@TargetApi(value = Build.VERSION_CODES.M)
private static List<MPermissionResultEnum> findPermissionResult(Activity activity, String... permissions) {
boolean overM = isOverMarshmallow();
List<MPermissionResultEnum> result = new ArrayList<>();
for (String p : permissions) {
if (overM) {
if (activity.checkSelfPermission(p) == PackageManager.PERMISSION_GRANTED) {
result.add(MPermissionResultEnum.GRANTED);
} else {
if (!activity.shouldShowRequestPermissionRationale(p)) {
result.add(MPermissionResultEnum.DENIED_NEVER_ASK_AGAIN);
} else {
result.add(MPermissionResultEnum.DENIED);
}
}
} else {
result.add(MPermissionResultEnum.GRANTED);
}
}
return result;
}
示例8: isAudioPermissionGranted
import android.app.Activity; //导入方法依赖的package包/类
private static boolean isAudioPermissionGranted(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (activity.checkSelfPermission(Manifest.permission.RECORD_AUDIO)
== PackageManager.PERMISSION_GRANTED) {
Timber.d("Permission is granted");
return true;
} else {
Timber.d("Permission is revoked");
ActivityCompat.requestPermissions(activity,
new String[]{Manifest.permission.RECORD_AUDIO},
activity.getResources().getInteger(R.integer.recorder_request));
return false;
}
} else { //permission is automatically granted on sdk<23 upon installation
Timber.d("Permission is granted");
return true;
}
}
示例9: isWritePermissionGranted
import android.app.Activity; //导入方法依赖的package包/类
private static boolean isWritePermissionGranted(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (activity.checkSelfPermission(WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
Timber.d("Permission is granted");
return true;
} else {
Timber.d("Permission is revoked");
ActivityCompat.requestPermissions(activity,
WRITE_PERM,
INT_DELETE_PICTURE_PERM);
return false;
}
} else { //permission is automatically granted on sdk<23 upon installation
Timber.d("Permission is granted");
return true;
}
}
示例10: hasStorageReadPermission
import android.app.Activity; //导入方法依赖的package包/类
private static boolean hasStorageReadPermission(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M ||
activity.checkSelfPermission(READ_EXTERNAL_STORAGE) == PERMISSION_GRANTED;
}
return true;
}
示例11: getDeniedPermissions
import android.app.Activity; //导入方法依赖的package包/类
/**
* 获取请求权限中需要授权的权限
*/
@TargetApi(Build.VERSION_CODES.M)
private static String[] getDeniedPermissions(Activity activity, String[] permissions) {
List<String> deniedPermissions = new ArrayList();
try {
for (String permission : permissions) {
if (activity.checkSelfPermission(permission) == PackageManager.PERMISSION_DENIED) {
deniedPermissions.add(permission);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return deniedPermissions.toArray(new String[deniedPermissions.size()]);
}
示例12: hasPermission
import android.app.Activity; //导入方法依赖的package包/类
/**
* Returns true if the Activity has access to a all given permission.
*/
public static boolean hasPermission(Activity activity, String[] permissions) {
for (String permission : permissions) {
if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
return true;
}
示例13: checkPermissionManuel
import android.app.Activity; //导入方法依赖的package包/类
public static int checkPermissionManuel(Activity mActivity, String permission, int requestCode){
int hasWriteContactsPermission = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
hasWriteContactsPermission = mActivity.checkSelfPermission(permission);
}else{
hasWriteContactsPermission = 0;
}
return hasWriteContactsPermission;
}
示例14: isGrantExternalRW
import android.app.Activity; //导入方法依赖的package包/类
/**
* 6.0以上权限
*
* @param activity
* @return
*/
public static boolean isGrantExternalRW(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && activity.checkSelfPermission(
Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
activity.requestPermissions(new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
}, 1);
return false;
}
return true;
}
示例15: requestPermission
import android.app.Activity; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.M)
public static void requestPermission(Activity activity, final String permission,
final int reqCode) {
// if (checkSelfPermission(Manifest.permission.READ_CONTACTS) !=
// PackageManager.PERMISSION_GRANTED) {
//
// requestPermissions(new String[]{Manifest.permission.READ_CONTACTS},
// REQUEST_CONTACT_PERMISSION);
// }
if (activity.checkSelfPermission(permission) !=
PackageManager.PERMISSION_GRANTED) {
activity.requestPermissions(new String[]{permission}, reqCode);
}
}