Android 权限:电话:读取电话状态和身份
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1747178/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android permissions: Phone Calls: read phone state and identity
提问by Mike Kale
My android app has nothing to do with phone calls, but I'm seeing that when I install a debug build on my test device it requires "Phone Calls: read phone state and identity" permissions. (I make no mention of this in AndroidManifest.xml
).
我的 android 应用程序与电话无关,但我看到当我在测试设备上安装调试版本时,它需要“电话呼叫:读取电话状态和身份”权限。(我在 中没有提到这一点AndroidManifest.xml
)。
I'd like to have the minimum possible permissions, and wondered if anyone knew how to get rid of this? I commented out the part where I was logging some stuff from Build.MODEL
, Build.VERSION.*
, etc. I also commented out the part where I was detecting the landscape/portrait orientation thinking that that might be the "phone state". But neither of those seemed to remove that permission required.
我想拥有尽可能低的权限,并想知道是否有人知道如何摆脱这个?我注释掉了我从Build.MODEL
、Build.VERSION.*
等中记录一些东西的部分。我还注释掉了我检测横向/纵向方向的部分,认为这可能是“电话状态”。但这些似乎都没有删除所需的许可。
I found this bug report: http://code.google.com/p/android/issues/detail?id=4101but it's marked working-as-intended with a note about permissions being correct from the market but not otherwise. Is this other people's experience? (I'd hate to have to publish to the market just to test that out.) Otherwise, does anyone know if there's an API I can avoid calling that will make it so my app doesn't need this permission?
我发现了这个错误报告:http: //code.google.com/p/android/issues/detail?id=4101但它被标记为按预期工作,并附有关于市场许可正确的注释,但不是其他情况。这是别人的经历吗?(我不想发布到市场只是为了测试它。)否则,有没有人知道是否有我可以避免调用的 API,这将使我的应用程序不需要此权限?
Thanks!
谢谢!
回答by Mike Kale
(Answering my own question in case anyone else runs into this problem and searches for it.)
(回答我自己的问题,以防其他人遇到此问题并进行搜索。)
Digging around in PackageParser.java in the android source, I found out that the system will automatically assign
在android源码中的PackageParser.java中挖了下,发现系统会自动赋值
android.permission.WRITE_EXTERNAL_STORAGE and
android.permission.READ_PHONE_STATE
to any app that declares a targetSdk version of less than 4 (donut). There must be a compatibility reason for this, maybe apps targeting older versions could assume they had these permissions without declaring them explicitly. So, if you don't want these permissions added to your app implicitly, add a section like the following in AndroidManifest.xml
任何声明 targetSdk 版本小于 4(甜甜圈)的应用。必须有一个兼容性原因,也许针对旧版本的应用程序可以假设他们拥有这些权限,而无需明确声明它们。因此,如果您不想将这些权限隐式添加到您的应用程序中,请在 AndroidManifest.xml 中添加如下所示的部分
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="4" />
That is all.
就这些。
Have fun, -Mike
玩得开心,-迈克
回答by Mark B
Android 1.6 changelog: http://developer.android.com/sdk/android-1.6.html#api
Android 1.6 更新日志:http: //developer.android.com/sdk/android-1.6.html#api
WRITE_EXTERNAL_STORAGE: Allows an application to write to external storage. Applications using API Level 3 and lower will be implicitly granted this permission (and this will be visible to the user); Applications using API Level 4 or higher must explicitly request this permission.
WRITE_EXTERNAL_STORAGE:允许应用程序写入外部存储。使用 API 级别 3 及更低级别的应用程序将被隐式授予此权限(并且这对用户可见);使用 API 级别 4 或更高级别的应用程序必须明确请求此权限。
But that is only one of them. For some reason the official change log is missing the info about READ_PHONE_STATE. The full story is cleared up here: http://blogs.zdnet.com/Burnette/?p=1369&page=3
但这只是其中之一。出于某种原因,官方更改日志缺少有关 READ_PHONE_STATE 的信息。完整的故事在这里澄清:http: //blogs.zdnet.com/Burnette/?p=1369&page=3
New permissions. 1.6 programs must explicitly request the WRITE_EXTERNAL_STORAGEpermission to be able to modify the contents of the SD card, and they must explicitly request the READ_PHONE_STATEpermission to be able to be able to retrieve phone state info. Apps targeting earlier versions will always request these permissions implicitly.
新权限。1.6 程序必须显式请求 WRITE_EXTERNAL_STORAGE权限才能修改SD卡的内容,并且必须显式请求READ_PHONE_STATE权限才能检索手机状态信息。面向早期版本的应用程序将始终隐式请求这些权限。
So as you can see, there is no way to publish an app targeted at 1.5 or earlier without requesting those permissions when installed on phones running 1.6 or higher.
因此,如您所见,如果安装在运行 1.6 或更高版本的手机上,则无法在不请求这些权限的情况下发布针对 1.5 或更早版本的应用程序。