當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。