android.content.Context.checkCallingOrSelfPermission()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(211)

本文整理了Java中android.content.Context.checkCallingOrSelfPermission()方法的一些代码示例,展示了Context.checkCallingOrSelfPermission()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.checkCallingOrSelfPermission()方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:checkCallingOrSelfPermission

Context.checkCallingOrSelfPermission介绍

暂无

代码示例

代码示例来源:origin: nostra13/Android-Universal-Image-Loader

private static boolean hasExternalStoragePermission(Context context) {
    int perm = context.checkCallingOrSelfPermission(EXTERNAL_STORAGE_PERMISSION);
    return perm == PackageManager.PERMISSION_GRANTED;
  }
}

代码示例来源:origin: square/picasso

static boolean hasPermission(Context context, String permission) {
 return context.checkCallingOrSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
}

代码示例来源:origin: daniulive/SmarterStreaming

/**
 * 检查是否有权限
 * 
 * @param context
 * @return
 */
private static boolean hasExternalStoragePermission(Context context) {
  int perm = context
      .checkCallingOrSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE");
  return perm == 0;
}

代码示例来源:origin: daniulive/SmarterStreaming

/**
   * 检查是否有权限
   *
   * @param context
   * @return
   */
  private static boolean hasExternalStoragePermission(Context context) {
    int perm = context.checkCallingOrSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE");
    return perm == 0;
  }
}

代码示例来源:origin: facebook/facebook-android-sdk

public static boolean hasPermission(Context context, String permission) {
  return context.checkCallingOrSelfPermission(permission) ==
   PackageManager.PERMISSION_GRANTED;
}

代码示例来源:origin: lovetuzitong/MultiImageSelector

private static boolean hasExternalStoragePermission(Context context) {
  int perm = context.checkCallingOrSelfPermission(EXTERNAL_STORAGE_PERMISSION);
  return perm == PackageManager.PERMISSION_GRANTED;
}

代码示例来源:origin: nisrulz/sensey

/**
 * Check permission boolean.
 *
 * @param context    the context
 * @param permission the permission
 * @return the boolean
 */
boolean checkPermission(Context context, String permission) {
  return context.checkCallingOrSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
}

代码示例来源:origin: oasisfeng/condom

@Override public int checkCallingOrSelfPermission(String permission) {
  return mBase.checkCallingOrSelfPermission(permission);
}

代码示例来源:origin: lingochamp/FileDownloader

public static boolean checkPermission(String permission) {
  final int perm = FileDownloadHelper.getAppContext()
      .checkCallingOrSelfPermission(permission);
  return perm == PackageManager.PERMISSION_GRANTED;
}

代码示例来源:origin: facebook/facebook-android-sdk

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);
    }
  }
}

代码示例来源:origin: ankidroid/Anki-Android

private boolean hasReadWritePermission() {
  if (BuildConfig.DEBUG) {    // Allow self-calling of the provider only in debug builds (e.g. for unit tests)
    return mContext.checkCallingOrSelfPermission(READ_WRITE_PERMISSION) == PackageManager.PERMISSION_GRANTED;
  }
  return mContext.checkCallingPermission(READ_WRITE_PERMISSION) == PackageManager.PERMISSION_GRANTED;
}

代码示例来源:origin: square/picasso

private Dispatcher createDispatcher(ExecutorService service, boolean scansNetworkChanges) {
 when(connectivityManager.getActiveNetworkInfo()).thenReturn(scansNetworkChanges ? mock(NetworkInfo.class) : null);
 when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityManager);
 when(context.checkCallingOrSelfPermission(anyString())).thenReturn(
   scansNetworkChanges ? PERMISSION_GRANTED : PERMISSION_DENIED);
 return new Dispatcher(context, service, new Handler(Looper.getMainLooper()), cache, stats);
}

代码示例来源:origin: lingochamp/FileDownloader

private static void mockContextNoWifiState(Context context) {
  when(context.checkCallingOrSelfPermission(anyString()))
      .thenReturn(PackageManager.PERMISSION_GRANTED);
  final ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
  when(context.getSystemService(Context.CONNECTIVITY_SERVICE))
      .thenReturn(connectivityManager);
  // not wifi.
  when(connectivityManager.getActiveNetworkInfo()).thenReturn(null);
}

代码示例来源:origin: lingochamp/okdownload

public static boolean checkPermission(String permission) {
  final int perm = OkDownload.with().context().checkCallingOrSelfPermission(permission);
  return perm == PackageManager.PERMISSION_GRANTED;
}

代码示例来源:origin: AltBeacon/android-beacon-library

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void requestModelMapFromWeb() {
  if (mContext.checkCallingOrSelfPermission("android.permission.INTERNET") != PackageManager.PERMISSION_GRANTED) {
    LogManager.w(TAG, "App has no android.permission.INTERNET permission.  Cannot check for distance model updates");
    return;

代码示例来源:origin: lingochamp/okdownload

@Test
public void inspectNetworkOnWifi() throws IOException {
  final DownloadTask task = mock(DownloadTask.class);
  when(task.isWifiRequired()).thenReturn(true);
  final Context context = mock(Context.class);
  final OkDownload okDownload = OkDownload.with();
  doReturn(context).when(okDownload).context();
  doReturn(PackageManager.PERMISSION_DENIED).when(context)
      .checkCallingOrSelfPermission(anyString());
  thrown.expect(IOException.class);
  thrown.expectMessage("required for access network state but don't have the "
      + "permission of Manifest.permission.ACCESS_NETWORK_STATE, please declare this "
      + "permission first on your AndroidManifest, so we can handle the case of "
      + "downloading required wifi state.");
  strategy.inspectNetworkOnWifi(task);
  strategy.isHasAccessNetworkStatePermission = true;
  final ConnectivityManager manager = mock(ConnectivityManager.class);
  doReturn(manager).when(context).getSystemService(eq(Context.CONNECTIVITY_SERVICE));
  doReturn(null).when(manager).getActiveNetworkInfo();
  thrown.expect(NetworkPolicyException.class);
  thrown.expectMessage("Only allows downloading this task on the wifi network type!");
  strategy.inspectNetworkOnWifi(task);
  final NetworkInfo info = mock(NetworkInfo.class);
  doReturn(info).when(manager).getActiveNetworkInfo();
  doReturn(ConnectivityManager.TYPE_WIFI).when(info).getType();
  strategy.inspectNetworkOnWifi(task);
}

代码示例来源:origin: aws-amplify/aws-sdk-android

private boolean hasPermission(final Context context, final String permission) {
    int res = context.checkCallingOrSelfPermission(permission);
    return (res == PackageManager.PERMISSION_GRANTED);
  }
}

代码示例来源:origin: aws-amplify/aws-sdk-android

private boolean hasPermission(final Context context, final String permission) {
    int res = context.checkCallingOrSelfPermission(permission);
    return (res == PackageManager.PERMISSION_GRANTED);
  }
}

代码示例来源:origin: stackoverflow.com

public static class PackageUtil {

  static boolean checkPermission(Context context, String accessFineLocation) {

    int res = context.checkCallingOrSelfPermission(accessFineLocation);
    return (res == PackageManager.PERMISSION_GRANTED);

  }

}

代码示例来源:origin: guolindev/giffun

public ConnectivityMonitor build(Context context, 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();
    }
  }
}

相关文章

Context类方法