通过听的BroadcastReceiver来电,而不PhoneStateIntentReceiver或PhoneStateListener而不、BroadcastReceiver、PhoneState

2023-09-05 00:05:12 作者:恒星储藏室

有没有办法通过扩展的BroadcastReceiver收听操作系统的广播收听来电,而无需使用PhoneStateIntentReceiver或PhoneStateListener。 也请告诉我会有什么行动和权限清单。

我试着以下,但它不工作的来电,但工作传出

应用程序的只有一个.java文件如下(应用程序只有一个.java文件和一个清单文件)

 包com.crsardar.media.audio;

进口android.content.BroadcastReceiver;
进口android.content.Context;
进口android.content.Intent;
进口android.util.Log;

公共类IncommingCallReceiverCRS扩展的BroadcastReceiver {

    @覆盖
    公共无效的onReceive(上下文的背景下,意图意图){
        Log.e(Chitta:,它的工作);
    }
}
 

清单

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
      包=com.crsardar.media.audio
      安卓版code =1
      机器人:VERSIONNAME =1.0>
  <应用机器人:图标=@可绘制/图标机器人:标签=@字符串/ APP_NAME>

    <接收器的Andr​​oid版本:NAME =IncommingCallReceiverCRS机器人:启用=真正的>
        <意向滤光器>
            !<  - 操作机器人:名称=android.intent.action.NEW_OUTGOING_CALL/  - >
            <作用机器人:名称=android.intent.action.ANSWER>
            <类机器人:名称=android.intent.category.DEFAULT/>
        &所述; /意图滤光器>
    < /接收器>

  < /用途>

  <使用-权限的Andr​​oid:名称=android.permission.PROCESS_OUTGOING_CALLS/>
  <使用-权限的Andr​​oid:名称=android.permission.READ_PHONE_STATE/>
  <使用-权限的Andr​​oid:名称=android.permission.RECORD_AUDIO/>
< /舱单>
 

解决方案 21.BroadcastReceiver的静态使用

您已经于您的清单中定义的行为是不正确。这是一个动作意图,可以用来接听电话,而不是监控来电。

您可以使用两个广播接收机的听ACTION_PHONE_STATE_CHANGED和NEW_OUTGOING_CALL广播意图。

当有新来电的ACTION_PHONE_STATE_CHANGED将被接收,来电应答或挂断(见文档收到此意向的群众演员)。

当有新的呼出放置在您的设备上的NEW_OUTGOING_CALL将被接受。

至于权限,我觉得你得到了它有关的权利在你的清单(我假设RECORD_AUDIO许可用于别的东西在你的应用程序)

Is there any way to listen to incoming calls by extending BroadcastReceiver to listen to OS's broadcast,without using PhoneStateIntentReceiver or PhoneStateListener. Also please tell me what will be action and permissions in manifest.

I've tried with as follows but it is not working for incoming calls but working for outgoing

The only one .java file of app is as follows(the app only one .java file and one manifest file)

package com.crsardar.media.audio;

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

public class IncommingCallReceiverCRS extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.e("Chitta : ", "Its working");          
    }
}

manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.crsardar.media.audio"
      android:versionCode="1"
      android:versionName="1.0">
  <application android:icon="@drawable/icon" android:label="@string/app_name">

    <receiver android:name="IncommingCallReceiverCRS" android:enabled="true"> 
        <intent-filter>
            <!--action android:name="android.intent.action.NEW_OUTGOING_CALL"/-->
            <action  android:name="android.intent.action.ANSWER" >
            <category  android:name="android.intent.category.DEFAULT" /> 
        </intent-filter>
    </receiver>

  </application>

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

解决方案

The action you have defined in your manifest is incorrect. this is an Action Intent that can be used to answer a call and not monitor incoming calls.

You can use two broadcast receivers that listen to ACTION_PHONE_STATE_CHANGED and NEW_OUTGOING_CALL broadcast intents.

The ACTION_PHONE_STATE_CHANGED will be received when there is a new incoming call, call answered or hangup (See the documentation for the EXTRAs received with this Intent).

The NEW_OUTGOING_CALL will be received when there is a new outgoing call placed on your device.

As for permissions, I think you got it about right in your manifest (I assume the RECORD_AUDIO permission is used for something else in your application)