Java Code Examples for android.app.Activity#checkCallingOrSelfPermission()

The following examples show how to use android.app.Activity#checkCallingOrSelfPermission() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaiduOauthImplicitGrant.java    From dcs-sdk-java with Apache License 2.0 5 votes vote down vote up
/**
 * 通过Dialog UI展示用户登录、授权页
 *
 * @param activity     需要展示Dialog UI的Activity
 * @param permissions  需要请求的环境
 * @param listener     用于回调的listener接口方法
 * @param redirectUrl  回调地址
 * @param responseType 授权请求的类型
 */
private void authorize(Activity activity,
                       String[] permissions,
                       boolean isForceLogin,
                       boolean isConfirmLogin,
                       final BaiduDialogListener listener,
                       String redirectUrl, String responseType) {
    CookieSyncManager.createInstance(activity);
    Bundle params = new Bundle();
    params.putString("client_id", this.cliendId);
    params.putString("redirect_uri", redirectUrl);
    params.putString("response_type", responseType);
    params.putString("display", DISPLAY_STRING);
    if (isForceLogin) {
        params.putString("force_login", "1");
    }
    if (isConfirmLogin) {
        params.putString("confirm_login", "1");
    }
    if (permissions == null) {
        permissions = DEFAULT_PERMISSIONS;
    }
    if (permissions != null && permissions.length > 0) {
        String scope = TextUtils.join(" ", permissions);
        params.putString("scope", scope);
    }
    params.putString("qrcode", "1");
    String url = OAUTHORIZE_URL + "?" + CommonUtil.encodeUrl(params);
    LogUtil.d(LOG_TAG, "url:" + url);
    if (activity.checkCallingOrSelfPermission(Manifest.permission.INTERNET)
            != PackageManager.PERMISSION_GRANTED) {
        CommonUtil.showAlert(activity, "没有权限", "应用需要访问互联网的权限");
    } else {
        new BaiduDialog(activity, url, listener).show();
    }
}
 
Example 2
Source File: PermissionUtils.java    From CumulusTV with MIT License 4 votes vote down vote up
public static boolean isEnabled(Activity activity, String permission) {
    return activity.checkCallingOrSelfPermission(permission)
            == PackageManager.PERMISSION_GRANTED;
}