为什么 play-services-location 需要 android.permission.WRITE_EXTERNAL_STORAGE 和 android.permission.READ_EXTERNAL_STORAGE 权限? [英] Why does play-services-location need the android.permission.WRITE_EXTERNAL_STORAGE and android.permission.READ_EXTERNAL_STORAGE permissions?

查看:206
本文介绍了为什么 play-services-location 需要 android.permission.WRITE_EXTERNAL_STORAGE 和 android.permission.READ_EXTERNAL_STORAGE 权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 AndroidManifest.xml 中的所有内容是:

All I have in AndroidManifest.xml is:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

将APK上传到开发者控制台后,新增了两个权限:

After uploading the APK to the developer console, it adds two new permissions:

我的 build.gradle:

My build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "net.perspiratron.ifpaprofile"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 3
        versionName "1.2"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
//    wearApp project(':wear')
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.google.android.gms:play-services-analytics:7.5.0'
    compile 'com.google.android.gms:play-services-location:7.5.0'
    compile 'com.jjoe64:graphview:4.0.0'
}

我唯一添加的是 play-services-location.为什么这个库需要它?

The only thing that I added was play-services-location. Why does this library need it?

推荐答案

简短回答:我认为 play-services-location 不需要这些权限.它似乎也不需要 android.permission.ACCESS_NETWORK_STATEandroid.permission.INTERNET,它们也在添加中.

Short answer: I don't believe play-services-location does need those permissions. Neither does it seem to need android.permission.ACCESS_NETWORK_STATE or android.permission.INTERNET, which are also being added.

更长的答案:查看我的清单合并日志,似乎所有这四个权限都是应 play-services-maps 的请求包含的,其中 -location 自行链接.我的应用没有使用 -maps,只使用 -location.

Longer answer: Looking at my manifest merger log, it appears that all four of these permissions are being included at the request of play-services-maps, which -location is linking in of its own accord. My app isn't using -maps, just -location.

此外,我发现这种行为刚刚出现在 play-services-location 7.5.0 版本中;之前的版本不包含 -maps,也不添加这些权限.

Further, I've found that this behavior just appeared in version 7.5.0 of play-services-location; prior versions didn't include -maps, and don't add those permissions.

我实际上怀疑与 play-services-maps 的这种连接是偶然的,将在未来的 GMS 版本中删除.

I actually suspect that this connection to play-services-maps is accidental, and will be removed in a future release of GMS.

按照 Mark Murphy (CommonsWare) 提供的链接,您可以通过在清单中添加以下几行来从您的应用中删除这些权限:

Following up on the link given by Mark Murphy (CommonsWare), you can remove these permissions from your app by adding the following lines to your manifest:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" tools:node="remove" />
<uses-permission android:name="android.permission.INTERNET" tools:node="remove" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:node="remove" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove" />

请注意,您还需要 xmlns:tools="http://schemas.android.com/tools" 在您的开头 <manifest ... >代码> 元素使这些工作.通常的警告适用:执行此步骤后,我的应用运行良好,但 YMMV.

Note that you'll also need xmlns:tools="http://schemas.android.com/tools" in your opening <manifest ... > element to make these work. And the usual caveats apply: my app worked fine after taking this step, but YMMV.

2015 年 9 月 10 日更新:Mark Murphy (@commonsware) 已完成在他的博客上写了一篇关于这个问题的优秀文章,包括对我的解决方案风险的讨论.

Update 10 Sep 2015: Mark Murphy (@commonsware) has done an excellent writeup on this issue on his blog, including a discussion of the risks of my solution.

这篇关于为什么 play-services-location 需要 android.permission.WRITE_EXTERNAL_STORAGE 和 android.permission.READ_EXTERNAL_STORAGE 权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆