requestPermissions对于android 8.1 API 27上的READ_CALL_LOG和WRITE_CALL_LOG不起作用

时间:2018-05-17 22:44:53

标签: android permissions manifest

我一直试图访问呼叫历史记录,但请求权限似乎不起作用

清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.stanrares.firstapp">

    <uses-permission android:name="android.permission.READ_CALL_LOG" />
    <uses-permission android:name="android.permission.WRITE_CALL_LOG" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />

请求权限的函数:

    public void EnableRuntimePermissionToAccessCallLogs()
        {
            Log.i(TAG,"EnableRuntimePermissionToAccessCallLogs called");

            if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED)
            {
                Log.i(TAG,"giving read call log permission");
                // TODO: Consider calling
                //    ActivityCompat#requestPermissions
                ActivityCompat.requestPermissions(getActivity(),
                        new String[]{Manifest.permission.READ_CALL_LOG},
                        1);
                Log.i(TAG,"giving read call log permission 2");
            }

            if(ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_CALL_LOG) != PackageManager.PERMISSION_GRANTED)
            {
                Log.i(TAG,"giving write call log permission");
                ActivityCompat.requestPermissions(getActivity(),
                        new String[]{Manifest.permission.WRITE_CALL_LOG},
                        1);
                Log.i(TAG,"giving write call log permission 2");

            }
            Log.i(TAG,"EnableRuntimePermissionToAccessCallLogs called 2");

        }

我已经尝试使用工具删除清单文件中的命名空间

1 个答案:

答案 0 :(得分:0)

我认为您正在使用类似getActivity()。getContentResolver()。query之类的代码来获取调用日志。

然后,您需要提供一个ContentProvider来获取URI并实现查询。 API26对此进行了更改: https://developer.android.com/about/versions/oreo/android-8.0-changes#rmp

发布您的代码,然后我们可以找到解决方案。