我设计了一个可以从 SD 获取/设置资源的函数,如果没有从 sd 中找到,则从 Asset 中获取它,如果可能,将资产写回 SD此函数可以通过方法调用检查 SD 是否已挂载且可访问...
I design a function that may get/set a resource from SD and if not found from sd then take it from Asset and if possible write the asset back to SD This function may check by method invocation if SD is mounted and accessible...
boolean bSDisAvalaible = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);我设计的功能可以从一个应用程序(项目)使用到另一个应用程序(有或没有 android.permission.WRITE_EXTERNAL_STORAGE)
My designed function may be used from one app(project) to another (with or without android.permission.WRITE_EXTERNAL_STORAGE)
然后我想检查当前应用程序是否具有此特定权限,而无需使用 SecurityException.
Then I would like to check if the current application has this particular permission without playing with SecurityException.
是否存在一种不错"的方式来在运行时查询当前定义的权限?
Does it exist a "nice" way to consult current defined permissions at runtime ?
推荐答案您可以为此使用 Context.checkCallingorSelfPermission() 函数.下面是一个例子:
You can use Context.checkCallingorSelfPermission() function for this. Here is an example:
private boolean checkWriteExternalPermission() { String permission = android.Manifest.permission.WRITE_EXTERNAL_STORAGE; int res = getContext().checkCallingOrSelfPermission(permission); return (res == PackageManager.PERMISSION_GRANTED); }更多推荐
如何在运行时检查权限而不抛出 SecurityException?
发布评论