由于Android 6.0监听PhoneStateListener.LISTEN_DATA_CONNECTION_STATE的更改似乎不再需要READ_PHONE_STATE权限 [英] Since Android 6.0 listening to the PhoneStateListener.LISTEN_DATA_CONNECTION_STATE changes seems to no longer require READ_PHONE_STATE permission

查看:728
本文介绍了由于Android 6.0监听PhoneStateListener.LISTEN_DATA_CONNECTION_STATE的更改似乎不再需要READ_PHONE_STATE权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Android 6.0运行时权限应用到可监听运营商数据连接状态更改的应用程序中.我首先尝试仅从清单中删除READ_PHONE_STATE,以检查应用程序在何处需要许可.令我惊讶的是,该应用程序根本没有崩溃.

I'm applying Android 6.0 runtime permissions into an app which listens to carrier data connection state changes. I first tried to just remove the READ_PHONE_STATE from the manifest to check where the app requires the permission. To my surprise the app didn't crash at all.

此后,我尝试在两个6.0之前版本的设备上进行相同的安装,但实际上确实崩溃了.在我看来,Android 6.0不再需要权限.有什么办法可以确认这一点吗?

After this I've tried the same installation on two pre 6.0 devices which did actually crash on it. To me it seems like Android 6.0 does no longer require the permission. Is there any way to confirm this?

下面的行是6.0之前版本的设备崩溃的那一行:

The line below is the one on which the pre 6.0 devices crashes:

tm(TelephonyManager).listen(this, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);

推荐答案

有什么方法可以确认这一点吗?

Is there any way to confirm this?

是的,当注册事件类型LISTEN_CALL_STATE时,此 commit 会删除READ_PHONE_STATE的请求. c2>和LISTEN_DATA_CONNECTION_STATE:

Yes, this commit removes the request of READ_PHONE_STATE when register the event type LISTEN_CALL_STATE, LISTEN_DATA_ACTIVITY and LISTEN_DATA_CONNECTION_STATE:

Do not enforce PHONE_STATE_PERMISSION to register listener PHONE_STATE_PERMISSION should not be required to register to the following event types:
- PhoneStateListener.LISTEN_CALL_STATE
- PhoneStateListener.LISTEN_DATA_ACTIVITY
- PhoneStateListener.LISTEN_DATA_CONNECTION_STATE

In case of LISTEN_CALL_STATE, an empty string should be passed instead of incomingNumber, when caller has no PHONE_STATE_PERMISSION.

Bug: 21588537 Change-Id: I5b6d0308924f7e4cd13a983b8e0c9b3a5bbb119b

developer.android.com 上的文档已更新并正确显示不需要权限.

The documentation on developer.android.com was updated and correctly shows that the permission are not required.

如果除LISTEN_DATA_CONNECTION_STATE之外的其他原因,代码不需要权限READ_PHONE_STATE,则可以更改AndroidManifest.xml,在uses-permission上添加maxSdkVersion:

If your code doesn't need the permission READ_PHONE_STATE for other reason apart from LISTEN_DATA_CONNECTION_STATE you can change your AndroidManifest.xml adding maxSdkVersion to the uses-permission:

<uses-permission android:name="android.permission.READ_PHONE_STATE" android:maxSdkVersion="22" />

这篇关于由于Android 6.0监听PhoneStateListener.LISTEN_DATA_CONNECTION_STATE的更改似乎不再需要READ_PHONE_STATE权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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