本文整理匯總了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;
}