简体   繁体   English

为什么在安装过程中总是要求两个权限?

[英]Why are two permissions always requested during installation?

I'm building a tiny dummy app using the command line (no gradle) with just a single blank activity, no permissions, no support libraries (or any other libraries, Google Play, etc) and yet Android always prompts for these two permissions during installation: 我正在使用命令行(无gradle)构建一个微小的虚拟应用,该应用只有一个空白活动,没有权限,没有支持库(或任何其他库,Google Play等),而Android始终会在提示时提示这两个权限安装:

在此处输入图片说明

I understand how and why permissions get merged in when other libraries are included during a build, but my app has nothing included. 我了解在构建过程中包含其他库时如何以及为什么合并权限,但是我的应用程序未包含任何内容。 I've extracted and decoded the compiled AndroidManifest.xml from the resulting APK and there's no <uses-permission> tag anywhere inside it. 我已经从生成的APK中提取并解码了已编译的AndroidManifest.xml,并且其中没有任何<uses-permission>标签。

According to this question , the READ_PHONE_STATE is added if no minSdkVersion value is entered, but I have one declared in the manifest (which I can also see in the compiled manifest). 根据此问题 ,如果未输入minSdkVersion值,则添加READ_PHONE_STATE,但我在清单中声明了一个值(也可以在编译的清单中看到)。 Here is the source manifest: 这是源清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="dummy.testapp"
    versionCode="1">

    <uses-sdk minSdkVersion="20" targetSdkVersion="22" />

    <application
        android:label="TestApp No Perms"
        android:icon="@drawable/ic_launcher">

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

</manifest>

The single activity (MainActivity) just calls setContentView() on a blank layout. 单个活动(MainActivity)仅在空白布局上调用setContentView()

Can anyone shed any light as to why these permissions are always requested or how to prevent them from being prompted for? 任何人都无法阐明为何总是要求这些权限或如何防止提示它们的原因吗?

The answer came down to the missing android: prefix on the minSdkVersion and targetSdkVersion attributes. 答案归结为缺少的android: minSdkVersiontargetSdkVersion属性上的前缀。

Having no android: prefix doesn't cause any warnings or errors to be emitted from the resource compiler, but because of the missing prefix, the value is ignored when the APK manifest is parsed during installation. 没有android:前缀不会导致资源编译器发出任何警告或错误,但是由于缺少前缀,因此在安装过程中解析APK清单时将忽略该值。

The end result is that Android believes there is no minSdkVersion set and, as reported in Why does my app has the READ_PHONE_STATE permission although it's not declared in manifest? 最终结果是Android认为没有minSdkVersion设置,并且正如为什么我的应用未在清单中声明的​​原因为什么我的应用具有READ_PHONE_STATE权限中所述? , automagically prompts for the permissions. ,自动提示输入权限。

Adding in the android: prefix fixed the issue and allows the app to be installed with no permission prompts. android:前缀中添加android:此问题,并允许在没有权限提示的情况下安装该应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM