本文整理汇总了Java中android.content.pm.PackageManager.checkPermission方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.checkPermission方法的具体用法?Java PackageManager.checkPermission怎么用?Java PackageManager.checkPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.checkPermission方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkPermission
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static boolean checkPermission(Context context, String permission) {
boolean result = false;
if (Build.VERSION.SDK_INT >= 23) {
try {
Class<?> clazz = Class.forName("android.content.Context");
Method method = clazz.getMethod("checkSelfPermission", String.class);
int rest = (Integer) method.invoke(context, permission);
if (rest == PackageManager.PERMISSION_GRANTED) {
result = true;
} else {
result = false;
}
} catch (Exception e) {
result = false;
}
} else {
PackageManager pm = context.getPackageManager();
if (pm.checkPermission(permission, context.getPackageName()) == PackageManager.PERMISSION_GRANTED) {
result = true;
}
}
return result;
}
示例2: getAvailableRewriters
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Retrieve rewriter available as plugin for csipsimple.
*
* @param ctxt context of application
* @return A map of package name => Fancy name of rewriter
*/
public static Map<String, String> getAvailableRewriters(Context ctxt) {
if (AVAILABLE_REWRITERS == null) {
AVAILABLE_REWRITERS = new HashMap<String, String>();
PackageManager packageManager = ctxt.getPackageManager();
Intent it = new Intent(SipManager.ACTION_REWRITE_NUMBER);
List<ResolveInfo> availables = packageManager.queryBroadcastReceivers(it, 0);
for (ResolveInfo resInfo : availables) {
ActivityInfo actInfos = resInfo.activityInfo;
Log.d(THIS_FILE, "Found rewriter " + actInfos.packageName + " " + actInfos.name);
if (packageManager.checkPermission(permission.PROCESS_OUTGOING_CALLS,
actInfos.packageName) == PackageManager.PERMISSION_GRANTED) {
String packagedActivityName = (new ComponentName(actInfos.packageName,
actInfos.name)).flattenToString();
AVAILABLE_REWRITERS.put(packagedActivityName,
(String) resInfo.loadLabel(packageManager));
}
}
}
return AVAILABLE_REWRITERS;
}
示例3: getDynActivityPlugins
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static Map<String, DynActivityPlugin> getDynActivityPlugins(Context ctxt, String action){
if(!CACHED_ACTIVITY_RESOLUTION.containsKey(action)) {
HashMap<String, DynActivityPlugin> plugins = new HashMap<String, DynActivityPlugin>();
PackageManager packageManager = ctxt.getPackageManager();
Intent it = new Intent(action);
List<ResolveInfo> availables = packageManager.queryIntentActivities(it, 0);
for(ResolveInfo resInfo : availables) {
ActivityInfo actInfos = resInfo.activityInfo;
if( packageManager.checkPermission(SipManager.PERMISSION_USE_SIP, actInfos.packageName) == PackageManager.PERMISSION_GRANTED) {
ComponentName cmp = new ComponentName(actInfos.packageName, actInfos.name);
DynActivityPlugin dynInfos;
dynInfos = new DynActivityPlugin(actInfos.loadLabel(packageManager).toString(), action,
cmp, actInfos.metaData);
plugins.put(cmp.flattenToString(), dynInfos);
}
}
CACHED_ACTIVITY_RESOLUTION.put(action, plugins);
}
return CACHED_ACTIVITY_RESOLUTION.get(action);
}
示例4: checkPermission
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@SuppressLint("NewApi")
public static boolean checkPermission(Context context, String permission) {
boolean result = false;
if (Build.VERSION.SDK_INT >= 23) {
try {
Class<?> clazz = Class.forName("android.content.Context");
Method method = clazz.getMethod("checkSelfPermission", String.class);
int rest = (Integer) method.invoke(context, permission);
result = rest == PackageManager.PERMISSION_GRANTED;
} catch (Exception e) {
result = false;
}
} else {
PackageManager pm = context.getPackageManager();
if (pm.checkPermission(permission, context.getPackageName()) == PackageManager.PERMISSION_GRANTED) {
result = true;
}
}
return result;
}
示例5: hasPermission
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static boolean hasPermission(Context context, String permission) {
if (context != null && !TextUtils.isEmpty(permission)) {
try {
PackageManager packageManager = context.getPackageManager();
if (packageManager != null) {
if (PackageManager.PERMISSION_GRANTED == packageManager.checkPermission(permission, context
.getPackageName())) {
return true;
}
Log.d("AppUtils", "Have you declared permission " + permission + " in AndroidManifest.xml ?");
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
return false;
}
示例6: checkPremission
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* 权限检测
*
* @param permissions 权限的名称
* @return
*/
public boolean checkPremission(String... permissions) {
boolean allHave = true;
PackageManager pm = getPackageManager();
for (String permission : permissions) {
switch (pm.checkPermission(permission, getApplication().getPackageName())) {
case PERMISSION_GRANTED:
allHave = allHave && true;
continue;
case PERMISSION_DENIED:
allHave = allHave && false;
continue;
}
}
return allHave;
}
示例7: getDynCodecPlugins
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Retrieve all dynamic codec plugins available in the platform
* It will resolve for a given action available sip plugins
* @param ctxt Context of the application
* @param action Action of the plugin to be resolved
* For example {@link SipManager#ACTION_GET_EXTRA_CODECS}, {@link SipManager.ACTION_GET_VIDEO_PLUGIN}
* @return a map containing plugins infos and registrered component name as key
*/
public static Map<String, DynCodecInfos> getDynCodecPlugins(Context ctxt, String action){
if(!CACHED_RESOLUTION.containsKey(action)) {
HashMap<String, DynCodecInfos> plugins = new HashMap<String, DynCodecInfos>();
PackageManager packageManager = ctxt.getPackageManager();
Intent it = new Intent(action);
List<ResolveInfo> availables = packageManager.queryBroadcastReceivers(it, 0);
for(ResolveInfo resInfo : availables) {
ActivityInfo actInfos = resInfo.activityInfo;
if( packageManager.checkPermission(SipManager.PERMISSION_CONFIGURE_SIP, actInfos.packageName) == PackageManager.PERMISSION_GRANTED) {
ComponentName cmp = new ComponentName(actInfos.packageName, actInfos.name);
DynCodecInfos dynInfos;
try {
dynInfos = new DynCodecInfos(ctxt, cmp);
plugins.put(cmp.flattenToString(), dynInfos);
} catch (NameNotFoundException e) {
Log.e(THIS_FILE, "Error while retrieving infos from dyn codec ", e);
}
}
}
CACHED_RESOLUTION.put(action, plugins);
}
return CACHED_RESOLUTION.get(action);
}
示例8: hasBasePhoneAuth
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private boolean hasBasePhoneAuth() {
// TODO Auto-generated method stub
PackageManager pm = this.getPackageManager();
for (String auth : authBaseArr) {
if (pm.checkPermission(auth, this.getPackageName()) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
return true;
}
示例9: hasInternet
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public boolean hasInternet(Context context) {
if (mInternet == null) {
mInternet = false;
PackageManager pm = context.getPackageManager();
for (ApplicationInfo appInfo : mMapAppInfo.values())
if (pm.checkPermission("android.permission.INTERNET", appInfo.packageName) == PackageManager.PERMISSION_GRANTED) {
mInternet = true;
break;
}
}
return mInternet;
}
示例10: checkNetworkOn
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private boolean checkNetworkOn(Context context, int type) {
boolean isNetworkOn = false;
try {
PackageManager packageManager = context.getPackageManager();
if (packageManager.checkPermission("android.permission.ACCESS_NETWORK_STATE",
context.getPackageName()) == 0) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
isNetworkOn = connectivityManager.getNetworkInfo(type).isConnected();
}
} catch (Exception e) {
e.printStackTrace();
}
return isNetworkOn;
}
示例11: checkGpsOn
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private boolean checkGpsOn(Context context) {
PackageManager packageManager = context.getPackageManager();
if(packageManager.checkPermission("android.permission.ACCESS_FINE_LOCATION", context.getPackageName()) == 0) {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
return false;
} else {
return true;
}
}
return false;
}
示例12: isAllowUseCamera
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static Boolean isAllowUseCamera(PackageManager pm) {
boolean permission = (PackageManager.PERMISSION_GRANTED ==
pm.checkPermission("android.permission.CAMERA", "com.lipy.jotter"))
&& (PackageManager.PERMISSION_GRANTED ==
pm.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", "com.lipy.jotter"))
&& (PackageManager.PERMISSION_GRANTED ==
pm.checkPermission("android.permission.READ_EXTERNAL_STORAGE", "com.lipy.jotter"));
return permission;
}
示例13: checkPermissions
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static boolean checkPermissions(Context context, String... permissions) {
String pkgName = context.getPackageName();
PackageManager pm = context.getPackageManager();
if (permissions != null) {
for (String permission : permissions) {
if (PackageManager.PERMISSION_GRANTED != pm.checkPermission(permission, pkgName)) {
return false;
}
}
}
return true;
}
示例14: getAutoRunAppList
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public ArrayList<AppBean> getAutoRunAppList() {
PackageManager localPackageManager = mContext.getPackageManager();
Intent localIntent = new Intent("android.intent.action.MAIN");
localIntent.addCategory("android.intent.category.LAUNCHER");
List<ResolveInfo> localList = localPackageManager.queryIntentActivities(localIntent, 0);
ArrayList<AppBean> localArrayList = null;
Iterator<ResolveInfo> localIterator = null;
if (localList != null) {
localArrayList = new ArrayList<AppBean>();
localIterator = localList.iterator();
}
while (true) {
if (!localIterator.hasNext())
break;
ResolveInfo localResolveInfo = localIterator.next();
AppBean localAppBean = new AppBean();
localAppBean.setIcon(localResolveInfo.activityInfo.loadIcon(localPackageManager));
localAppBean.setName(localResolveInfo.activityInfo.loadLabel(localPackageManager).toString());
localAppBean.setPackageName(localResolveInfo.activityInfo.packageName);
localAppBean.setDataDir(localResolveInfo.activityInfo.applicationInfo.publicSourceDir);
String pkgName = localResolveInfo.activityInfo.packageName;
String permission = "android.permission.RECEIVE_BOOT_COMPLETED";
try {
PackageInfo mPackageInfo = mContext.getPackageManager().getPackageInfo(pkgName, 0);
if ((PackageManager.PERMISSION_GRANTED == localPackageManager.checkPermission(permission, pkgName)) && !((mPackageInfo.applicationInfo.flags & mPackageInfo.applicationInfo.FLAG_SYSTEM) > 0)) {
localArrayList.add(localAppBean);
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
return localArrayList;
}
示例15: hasPermissionForActivity
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Returns true if {@param srcPackage} has the permission required to start the activity from
* {@param intent}. If {@param srcPackage} is null, then the activity should not need
* any permissions
*/
public static boolean hasPermissionForActivity(Context context, Intent intent,
String srcPackage) {
PackageManager pm = context.getPackageManager();
ResolveInfo target = pm.resolveActivity(intent, 0);
if (target == null) {
// Not a valid target
return false;
}
if (TextUtils.isEmpty(target.activityInfo.permission)) {
// No permission is needed
return true;
}
if (TextUtils.isEmpty(srcPackage)) {
// The activity requires some permission but there is no source.
return false;
}
// Source does not have sufficient permissions.
if(pm.checkPermission(target.activityInfo.permission, srcPackage) !=
PackageManager.PERMISSION_GRANTED) {
return false;
}
if (!Utilities.ATLEAST_MARSHMALLOW) {
// These checks are sufficient for below M devices.
return true;
}
// On M and above also check AppOpsManager for compatibility mode permissions.
if (TextUtils.isEmpty(AppOpsManager.permissionToOp(target.activityInfo.permission))) {
// There is no app-op for this permission, which could have been disabled.
return true;
}
// There is no direct way to check if the app-op is allowed for a particular app. Since
// app-op is only enabled for apps running in compatibility mode, simply block such apps.
try {
return pm.getApplicationInfo(srcPackage, 0).targetSdkVersion >= Build.VERSION_CODES.M;
} catch (NameNotFoundException e) { }
return false;
}