设置 android:targetSdkVersion 如何影响 requestPermissions()

How setting android:targetSdkVersion influences requestPermissions()

我刚刚注意到如果未设置 targetSDKVersion 值(当您在项目设置中选择目标框架是 SDK 版本时会发生这种情况)然后调用 requestPermissions ALWAYS returns 已授予权限。

这里也提到了这种行为:

因此,我开始思考实际设置 targetSDKVersion 是一个好的做法。这是正确的吗?

正如 Android 开发人员的文档所说 targetSDKVersion :

An integer designating the API Level that the application targets. If not set, the default value equals that given to minSdkVersion. This attribute informs the system that you have tested against the target version and the system should not enable any compatibility behaviors to maintain your app's forward-compatibility with the target version. The application is still able to run on older versions (down to minSdkVersion).

如果您不设置它,默认情况下它等于 minSdkVersion 为 Android 的最新版本提供一些意外行为。 因此,最好定义您的 targetSDKVersion。