当前位置: 首页>>代码示例>>Java>>正文


Java Context.checkCallingOrSelfPermission方法代码示例

本文整理汇总了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;
}
 
开发者ID:miLLlulei,项目名称:Accessibility,代码行数:18,代码来源:PackageUsageHelper.java

示例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;
}
 
开发者ID:AnnyBaby,项目名称:Mvp-Retrofit-Rxjava-Rxbus,代码行数:26,代码来源:AppInfoUtils.java

示例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;
}
 
开发者ID:AnnyBaby,项目名称:Mvp-Retrofit-Rxjava-Rxbus,代码行数:25,代码来源:DevUtils.java

示例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;
}
 
开发者ID:Leanplum,项目名称:Leanplum-Android-SDK,代码行数:26,代码来源:LeanplumManifestHelper.java

示例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();
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:DefaultConnectivityMonitorFactory.java

示例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);
        }
    }
}
 
开发者ID:eviltnan,项目名称:kognitivo,代码行数:12,代码来源:Validate.java

示例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);
    }
}
 
开发者ID:kevalpatel2106,项目名称:smart-lens,代码行数:12,代码来源:CustomTestRunner.java

示例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();
}
 
开发者ID:dueros,项目名称:dcs-sdk-java,代码行数:15,代码来源:BaiduOauthImplicitGrant.java

示例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;
}
 
开发者ID:waylife,项目名称:ViewDebugHelper,代码行数:14,代码来源:AppUtil.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:12,代码来源:jm.java

示例11: hasPermission

import android.content.Context; //导入方法依赖的package包/类
static boolean hasPermission(Context context, String permission) {
  return context.checkCallingOrSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:4,代码来源:Utils.java

示例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);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:6,代码来源:b.java

示例13: checkForCameraPermission

import android.content.Context; //导入方法依赖的package包/类
private boolean checkForCameraPermission(Context context) {
  return context.checkCallingOrSelfPermission(Manifest.permission.CAMERA)
      == PackageManager.PERMISSION_GRANTED;
}
 
开发者ID:nisrulz,项目名称:lantern,代码行数:5,代码来源:Lantern.java

示例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;
}
 
开发者ID:architjn,项目名称:YAAB,代码行数:5,代码来源:PermissionChecker.java

示例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;
}
 
开发者ID:Zyj163,项目名称:yyox,代码行数:5,代码来源:FileUtils.java


注:本文中的android.content.Context.checkCallingOrSelfPermission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。