运行 时间权限应用级别或 activity 级别
Run time permission app level or activity level
在新的api版本android(API23)中,我们现在需要在运行时请求权限。我有一个非常基本的疑问,请求的权限是应用级别还是 activity。根据 this 文档,您必须在每次执行需要该权限的操作时检查您是否拥有该权限。那么这是否意味着权限是在应用级别授予的,但建议在 activity 级别进行检查?此外,建议按如下方式检查权限:
// Assume thisActivity is the current activity
int permissionCheck = ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.WRITE_CALENDAR);
在这里,我们清楚地看到权限的检查是通过传递activity的上下文来完成的。如果授予的权限是在应用程序级别,为什么我们需要 activity 上下文而不是应用程序上下文?(尽管该方法有可能在内部从 activity 上下文获取应用程序上下文。)
if the permission requested are app level or activity
Android 中的所有权限适用于整个应用程序。
So does this mean that the permission is granted at app level but its check has been suggested to be done at the activity level?
可以在任何地方通过 checkSelfPermission()
检查您是否有权限。 请求 用户许可必须从 activity 通过 requestPermissions()
完成。由此产生的权限授予将适用于您的整个应用。
If the permission given is at app level why do we require the activity context and not the application context?
任何 Context
都适用于 ContextCompat
方法。
在新的api版本android(API23)中,我们现在需要在运行时请求权限。我有一个非常基本的疑问,请求的权限是应用级别还是 activity。根据 this 文档,您必须在每次执行需要该权限的操作时检查您是否拥有该权限。那么这是否意味着权限是在应用级别授予的,但建议在 activity 级别进行检查?此外,建议按如下方式检查权限:
// Assume thisActivity is the current activity
int permissionCheck = ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.WRITE_CALENDAR);
在这里,我们清楚地看到权限的检查是通过传递activity的上下文来完成的。如果授予的权限是在应用程序级别,为什么我们需要 activity 上下文而不是应用程序上下文?(尽管该方法有可能在内部从 activity 上下文获取应用程序上下文。)
if the permission requested are app level or activity
Android 中的所有权限适用于整个应用程序。
So does this mean that the permission is granted at app level but its check has been suggested to be done at the activity level?
可以在任何地方通过 checkSelfPermission()
检查您是否有权限。 请求 用户许可必须从 activity 通过 requestPermissions()
完成。由此产生的权限授予将适用于您的整个应用。
If the permission given is at app level why do we require the activity context and not the application context?
任何 Context
都适用于 ContextCompat
方法。