READ_PHONE_STATE 的权限被拒绝 [重复]

Posted

技术标签:

【中文标题】READ_PHONE_STATE 的权限被拒绝 [重复]【英文标题】:Permission Denial for READ_PHONE_STATE [duplicate] 【发布时间】:2016-12-24 10:13:29 【问题描述】:

我正在开发需要在手机接听电话时收到通知的 android 应用程序。我使用 BroadcastReceiver 的方法,因为即使应用程序未处于活动状态,我也想获得有关来电的通知。因此,使用 TelephonyManager 和 PhoneStateListener 的方法不适合我的需要。 所以,我的应用程序在清单中有适当的权限:

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

它还在清单中正确注册广播接收器:

<receiver android:enabled="true" android:name=".CallReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
</receiver>

CallReceiver 类实现了 BroadcastReceiver,但是一旦我启动应用程序,它的 CallReceiver 的 onReceive 方法就永远不会被调用,也永远不会被调用。 原因是系统拒绝向我的广播接收器传递 Intent,因为每次电话响起时我都会在日志中发现以下消息:

W/BroadcastQueue: Permission Denial: receiving Intent  act=android.intent.action.PHONE_STATE flg=0x10 (has extras)  to com.example.incomingcall/.CallReceiver requires android.permission.READ_PRIVILEGED_PHONE_STATE due to sender android (uid 1000)
W/BroadcastQueue: Permission Denial: receiving Intent  act=android.intent.action.PHONE_STATE flg=0x10 (has extras)  to com.example.incomingcall/.CallReceiver requires android.permission.READ_PHONE_STATE due to sender android (uid 1000)

正如我所解释的,我已经在清单中放置了 READ_PHONE_STATE 权限,而此处指定的其他权限是无法放入清单中的系统权限。任何想法如何克服这个问题? 带有 Android 6.0.1 的 Nexus 6p 中显示此内容的设备

【问题讨论】:

***.com/questions/32635704/… 【参考方案1】:
if (ContextCompat.checkSelfPermission(thisActivity,Manifest.permission.READ_PHONE_STATE)!= PackageManager.PERMISSION_GRANTED) 

    // Should we show an explanation?
    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,Manifest.permission.READ_PHONE_STATE)) 

        // Show an expanation to the user *asynchronously* -- don't block
        // this thread waiting for the user's response! After the user
        // sees the explanation, try again to request the permission.

     else 

        // No explanation needed, we can request the permission.

        ActivityCompat.requestPermissions(thisActivity,
            new String[]Manifest.permission.READ_PHONE_STATE,
            MY_PERMISSIONS_REQUEST_READ_CONTACTS);

        // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
        // app-defined int constant. The callback method gets the
        // result of the request.
    

【讨论】:

以上是关于READ_PHONE_STATE 的权限被拒绝 [重复]的主要内容,如果未能解决你的问题,请参考以下文章

谷歌播放控制台应用程序因权限而被拒绝

尝试获取 READ_PHONE_STATE 权限时未显示 Android 权限对话框

为啥添加了 READ_PHONE_STATE 权限?

为啥添加了 READ_PHONE_STATE 权限?

测试READ_PHONE_STATE的Android M权限(危险权限)

警告您的 Apk 正在使用需要隐私政策的权限:(android.permission.READ_PHONE_STATE)