本文整理汇总了Java中android.content.Context.checkCallingOrSelfPermission方法的典型用法代码示例。如果您正苦于以下问题:Java Context.checkCallingOrSelfPermission方法的具体用法?Java Context.checkCallingOrSelfPermission怎么用?Java Context.checkCallingOrSelfPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Context
的用法示例。
在下文中一共展示了Context.checkCallingOrSelfPermission方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: usagePermissionCheck
import android.content.Context; //导入方法依赖的package包/类
public static boolean usagePermissionCheck(Context context) {
boolean granted = false;
if (context != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
try {
AppOpsManager appOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
int mode = appOps.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, android.os.Process.myUid(), context.getPackageName());
if (mode == AppOpsManager.MODE_DEFAULT) {
String permissionUsage = "android.permission.PACKAGE_USAGE_STATS";
granted = (context.checkCallingOrSelfPermission(permissionUsage) == PackageManager.PERMISSION_GRANTED);
} else {
granted = (mode == AppOpsManager.MODE_ALLOWED);
}
} catch (Throwable e) {
}
}
return granted;
}
示例2: getPhoneIMEI
import android.content.Context; //导入方法依赖的package包/类
/**
* 有做M上的权限兼容
* @param context
* @return
*/
public static String getPhoneIMEI(Context context) {
String deviceID = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int permissionResult = context.checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE);
if (permissionResult == PackageManager.PERMISSION_DENIED) {
permissionResult = context.checkCallingOrSelfPermission("android.permission.READ_PRIVILEGED_PHONE_STATE");
}
boolean isPermissionGranted = permissionResult == PackageManager.PERMISSION_GRANTED;
if (!isPermissionGranted) {
deviceID = getDeviceIDFromReflection(context);
} else {
deviceID = getDeviceIDFromSystem(context);
}
} else {
deviceID = getDeviceIDFromSystem(context);
}
Log.i(TAG,"getPhoneIMEI : " + deviceID);
return deviceID;
}
示例3: getDeviceID
import android.content.Context; //导入方法依赖的package包/类
/**
* 有做M上的权限兼容
* @param context
* @return
*/
public static String getDeviceID(Context context) {
String deviceID = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int permissionResult = context.checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE);
if (permissionResult == PackageManager.PERMISSION_DENIED) {
permissionResult = context.checkCallingOrSelfPermission("android.permission.READ_PRIVILEGED_PHONE_STATE");
}
boolean isPermissionGranted = permissionResult == PackageManager.PERMISSION_GRANTED;
if (!isPermissionGranted) {
deviceID = getDeviceIDFromReflection(context);
} else {
deviceID = getDeviceIDFromSystem(context);
}
} else {
deviceID = getDeviceIDFromSystem(context);
}
return deviceID;
}
示例4: checkPermission
import android.content.Context; //导入方法依赖的package包/类
public static boolean checkPermission(String permission, boolean definesPermission,
boolean logError) {
Context context = Leanplum.getContext();
if (context == null) {
return false;
}
int result = context.checkCallingOrSelfPermission(permission);
if (result != PackageManager.PERMISSION_GRANTED) {
String definition;
if (definesPermission) {
definition = "<permission android:name=\"" + permission +
"\" android:protectionLevel=\"signature\" />\n";
} else {
definition = "";
}
if (logError) {
Log.e("In order to use push notifications, you need to enable " +
"the " + permission + " permission in your AndroidManifest.xml file. " +
"Add this within the <manifest> section:\n" +
definition + "<uses-permission android:name=\"" + permission + "\" />");
}
return false;
}
return true;
}
示例5: build
import android.content.Context; //导入方法依赖的package包/类
@NonNull
public ConnectivityMonitor build(
@NonNull Context context,
@NonNull ConnectivityMonitor.ConnectivityListener listener) {
final int res = context.checkCallingOrSelfPermission("android.permission.ACCESS_NETWORK_STATE");
final boolean hasPermission = res == PackageManager.PERMISSION_GRANTED;
if (hasPermission) {
return new DefaultConnectivityMonitor(context, listener);
} else {
return new NullConnectivityMonitor();
}
}
示例6: hasInternetPermissions
import android.content.Context; //导入方法依赖的package包/类
public static void hasInternetPermissions(Context context, boolean shouldThrow) {
Validate.notNull(context, "context");
if (context.checkCallingOrSelfPermission(Manifest.permission.INTERNET) ==
PackageManager.PERMISSION_DENIED) {
if (shouldThrow) {
throw new IllegalStateException(NO_INTERNET_PERMISSION_REASON);
} else {
Log.w(TAG, NO_INTERNET_PERMISSION_REASON);
}
}
}
示例7: disableAnimations
import android.content.Context; //导入方法依赖的package包/类
/**
* Disable all animations by applying 0 scale to {@link #setSystemAnimationsScale(float)}.
*
* @param context Instance of the caller.
*/
private void disableAnimations(Context context) {
int permStatus = context.checkCallingOrSelfPermission(Manifest.permission.SET_ANIMATION_SCALE);
if (permStatus == PackageManager.PERMISSION_GRANTED) {
setSystemAnimationsScale(0.0f);
}
}
示例8: init
import android.content.Context; //导入方法依赖的package包/类
/**
* 初始化accesTokenManager等信息
*
* @param context 当前执行的上下文环境
*/
public void init(Context context) {
if (context.checkCallingOrSelfPermission(Manifest.permission.ACCESS_NETWORK_STATE)
!= PackageManager.PERMISSION_GRANTED) {
Log.w(LOG_TAG, "App miss permission android.permission.ACCESS_NETWORK_STATE! "
+ "Some mobile's WebView don't display page!");
}
this.accessTokenManager = new AccessTokenManager(context);
this.accessTokenManager.initToken();
}
示例9: getImei
import android.content.Context; //导入方法依赖的package包/类
/**
* get the current version of current application
*/
public static String getImei( Context context) {
if (TextUtils.isEmpty(imei)) {
if(context.checkCallingOrSelfPermission( Manifest.permission.READ_PHONE_STATE)== PackageManager.PERMISSION_GRANTED){
TelephonyManager tm = (TelephonyManager) context.getApplicationContext()
.getSystemService(Context.TELEPHONY_SERVICE);
imei = tm.getDeviceId();
}
}
return imei;
}
示例10: b
import android.content.Context; //导入方法依赖的package包/类
public static File b(boolean z) {
Context c = hn.a().c();
File file = null;
if (z && "mounted".equals(Environment.getExternalStorageState()) && (VERSION.SDK_INT >= 19 || c.checkCallingOrSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE") == 0)) {
file = c.getExternalCacheDir();
}
if (file == null) {
return c.getCacheDir();
}
return file;
}
示例11: hasPermission
import android.content.Context; //导入方法依赖的package包/类
static boolean hasPermission(Context context, String permission) {
return context.checkCallingOrSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
}
示例12: a
import android.content.Context; //导入方法依赖的package包/类
private static void a(Context context, String str) {
if ((context.checkCallingOrSelfPermission(str) == 0 ? 1 : null) == null) {
throw new SecurityException("Permission Denial: requires permission " + str);
}
}
示例13: checkForCameraPermission
import android.content.Context; //导入方法依赖的package包/类
private boolean checkForCameraPermission(Context context) {
return context.checkCallingOrSelfPermission(Manifest.permission.CAMERA)
== PackageManager.PERMISSION_GRANTED;
}
示例14: hasPermission
import android.content.Context; //导入方法依赖的package包/类
public static boolean hasPermission(Context context, String permission) {
int res = context.checkCallingOrSelfPermission(permission);
return res == PackageManager.PERMISSION_GRANTED;
}
示例15: hasExternalStoragePermission
import android.content.Context; //导入方法依赖的package包/类
private static boolean hasExternalStoragePermission(Context context) {
int perm = context.checkCallingOrSelfPermission(EXTERNAL_STORAGE_PERMISSION);
return perm == PackageManager.PERMISSION_GRANTED;
}