本文整理了Java中android.app.Activity.checkSelfPermission()
方法的一些代码示例,展示了Activity.checkSelfPermission()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.checkSelfPermission()
方法的具体详情如下:
包路径:android.app.Activity
类名称:Activity
方法名:checkSelfPermission
暂无
代码示例来源:origin: naman14/Timber
/**
* Returns true if the Activity has access to given permissions.
*/
public static boolean hasPermission(Activity activity, String permission) {
return activity.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
}
代码示例来源:origin: aa112901/remusic
/**
* 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;
}
代码示例来源:origin: naman14/Timber
/**
* 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;
}
代码示例来源:origin: aa112901/remusic
/**
* Returns true if the Activity has access to given permissions.
*/
public static boolean hasPermission(Activity activity, String permission) {
return activity.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
}
代码示例来源:origin: pili-engineering/PLDroidPlayer
@TargetApi(Build.VERSION_CODES.M)
private boolean addPermission(List<String> permissionsList, String permission) {
boolean ret = true;
if (mActivity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
permissionsList.add(permission);
ret = false;
}
return ret;
}
代码示例来源:origin: google/ExoPlayer
/**
* 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;
}
代码示例来源:origin: pili-engineering/PLDroidShortVideo
@TargetApi(Build.VERSION_CODES.M)
private boolean addPermission(List<String> permissionsList, String permission) {
boolean ret = true;
if (mActivity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
permissionsList.add(permission);
ret = false;
}
return ret;
}
代码示例来源:origin: lovedise/PermissionGen
@TargetApi(value = Build.VERSION_CODES.M)
public static List<String> findDeniedPermissions(Activity activity, String... permission){
List<String> denyPermissions = new ArrayList<>();
for(String value : permission){
if(activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED){
denyPermissions.add(value);
}
}
return denyPermissions;
}
代码示例来源:origin: UncorkedStudios/recordablesurfaceview
public static boolean hasPermissions(Activity activity) {
return (activity.checkSelfPermission(WRITE_EXTERNAL_STORAGE_PERMISSION) ==
PackageManager.PERMISSION_GRANTED) &&
(activity.checkSelfPermission(RECORD_AUDIO_PERMISSION) ==
PackageManager.PERMISSION_GRANTED);
}
代码示例来源:origin: brainysoon/cyberCar
/**
* Returns true if the Activity has access to given permissions.
*/
@TargetApi(23)
public static boolean hasPermission(Activity activity, String permission) {
return activity.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
}
代码示例来源:origin: brainysoon/cyberCar
/**
* Returns true if the Activity has access to a all given permission.
*/
@TargetApi(23)
public static boolean hasPermission(Activity activity, String[] permissions) {
for (String permission : permissions) {
if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
return true;
}
代码示例来源:origin: killer8000/FloatingBall
@TargetApi(Build.VERSION_CODES.M)
public static boolean checkPermission(Activity activity, int requestCode) {
String permission = requestPermissions[requestCode];
int result = activity.checkSelfPermission(permission);
if (result == PackageManager.PERMISSION_GRANTED) {
return true;
}
return false;
}
代码示例来源:origin: pili-engineering/QNRTC-Android
@TargetApi(Build.VERSION_CODES.M)
private boolean addPermission(List<String> permissionsList, String permission) {
boolean ret = true;
if (mActivity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
permissionsList.add(permission);
ret = false;
}
return ret;
}
代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer
void check() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (activity.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED ||
activity.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
return;
}
if (activity.isFinishing()) {
return;
}
activity.requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, REQUEST_CODE);
}
}
代码示例来源:origin: huangweicai/OkLibDemo
@TargetApi(value = Build.VERSION_CODES.M)
public static List<String> findDeniedPermissions(Activity activity, String... permission) {
List<String> denyPermissions = new ArrayList<>();
for (String value : permission) {
if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED) {
denyPermissions.add(value);
}
}
return denyPermissions;
}
代码示例来源:origin: CesarValiente/PermissionsSample
@Override
public boolean hasSelfPermission(String permission) {
if (!CommonUtils.isMarshmallowOrHigher()) {
return true;
}
return activity.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
}
代码示例来源:origin: akshay2211/PixImagePicker
@RequiresApi(api = Build.VERSION_CODES.M)
private static boolean addPermission(List<String> permissionsList, String permission, Activity ac) {
if (ac.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
permissionsList.add(permission);
// Check for Rationale Option
return ac.shouldShowRequestPermissionRationale(permission);
}
return true;
}
代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer
@Test
public void testCheckWithFineLocationGranted() {
// setup
when(activity.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION)).thenReturn(PackageManager.PERMISSION_DENIED);
when(activity.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)).thenReturn(PackageManager.PERMISSION_GRANTED);
// execute
fixture.check();
// validate
verify(activity).checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION);
verify(activity).checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION);
verify(activity, never()).isFinishing();
verify(activity, never()).requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PermissionChecker.REQUEST_CODE);
}
代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer
@Test
public void testCheckWithCoarseLocationGranted() {
// setup
when(activity.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION)).thenReturn(PackageManager.PERMISSION_GRANTED);
// execute
fixture.check();
// validate
verify(activity).checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION);
verify(activity, never()).checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION);
verify(activity, never()).isFinishing();
verify(activity, never()).requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PermissionChecker.REQUEST_CODE);
}
代码示例来源:origin: enricocid/LaunchEnr
static void performCall(Activity activity, String number) {
if (AndroidVersion.isAtLeastMarshmallow) {
if (activity.checkSelfPermission(Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
activity.requestPermissions(new String[]{Manifest.permission.CALL_PHONE}
, PermissionUtils.CALL_REQUEST_CODE);
} else {
call(activity, number);
}
} else {
call(activity, number);
}
}
内容来源于网络,如有侵权,请联系作者删除!