使用 Lint 分析代码以查找需要权限的调用

Analyze code with Lint for calls that require permissions

我将我的 targetSdkVersion 设置为 23,因此我想实现 "Requesting permissions at runtime"。 (参见 here

如果忘记检查权限,Lint直接调用 告诉你以下内容:

Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential `SecurityException'

这非常好,我想分析我的代码以进行任何可能的调用 忘记了,但我找不到必须 select 的 Lint 选项 在我的检查资料中。

检查是怎么称呼的? 谢谢!

首先点击 Hector the Inspector(在 Android Studio 的 bottom-right 处的一个留着小胡子的男人的小图标)。这将显示配置检查的选项。

然后您应在搜索栏中键入 'Permissions',并确保选中 "Constant and Resource Type Mismatches"。之后,这是 运行 通过分析 > 检查代码进行检查的简单案例。