gpt4 book ai didi

java - 拒绝广播接收器的权限

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:04:10 25 4
gpt4 key购买 nike

我正在尝试创建一个应用程序,当我拨出电话时它会输入一条日志消息。

但是,当我运行代码时,我得到了权限拒绝,尽管我已经输入了权限。

拒绝日志:

"09-04 02:35:50.535 1294-1666/? W/BroadcastQueue:权限拒绝:接收 Intent { act=android.intent.action.NEW_OUTGOING_CALL flg=0x10000010(有附加功能)} 到 samples.varma.packagecom .testreceive2/.CallReceiver 需要 android.permission.PROCESS_OUTGOING_CALLS 由于发件人 android (uid 1000)"

list 代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="samples.varma.packagecom.testreceive2" >
android:versionCode="1"
android:versionName="1.0">

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="23" />


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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >


<activity
android:name=".MainActivity"
android:enabled="true"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


<receiver
android:name=".CallReceiver">


<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"/>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
</application>


</manifest>

这是我的接收器的代码:

package samples.varma.packagecom.testreceive2;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;

public class CallReceiver extends BroadcastReceiver {
public CallReceiver() {
}

@Override
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (state == null) {
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.i("TAG", "Outgoing Number: " + number);
} else if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.i("TAG", "Incoming Number: " + number);
}
}
}

我对此很陌生,所以很有可能存在一些错误,或者我完全偏离了基础。无论如何,我将不胜感激任何指导。有谁知道我为什么会被拒绝?

谢谢

编辑:

即使我已经添加了电话状态权限,它也会给我这些权限拒绝。

特权电话状态权限是系统权限,因此我无法添加。

09-04 04:36:03.249    1294-1440/? W/BroadcastQueue﹕ Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x10 (has extras) } to samples.varma.packagecom.testreceive2/.CallReceiver requires android.permission.READ_PRIVILEGED_PHONE_STATE due to sender android (uid 1000)
09-04 04:36:03.271 1294-1308/? W/BroadcastQueue﹕ Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x10 (has extras) } to samples.varma.packagecom.testreceive2/.CallReceiver requires android.permission.READ_PHONE_STATE due to sender android (uid 1000)

1294-1308/? W/BroadcastQueue﹕ Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x10 (has extras) } to samples.varma.packagecom.testreceive2/.CallReceiver requires android.permission.READ_PHONE_STATE due to sender android (uid 1000)

最佳答案

我在 Android 模拟器上启动了相同的应用程序,但没有任何帮助,甚至

android:enabled="true"
android:exported="true"

解决方案是转到“设置”->“应用程序”->“我的应用程序”->“权限”->“打开电话权限”。

Android Phone Permission for Application

关于java - 拒绝广播接收器的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32409741/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com