当接听拨出呼叫时,OnReceive BroadcastReceiver不会被触发

时间:2018-02-26 20:13:55

标签: android xamarin android-broadcastreceiver telephonymanager outgoing-call

我想在接听时检测拨出电话,我使用带有以下代码的BroadcastReciever:

class OutgoingReceiver : BroadcastReceiver
{
    public override void OnReceive(Context context, Intent intent)
    {
    string number = intent.GetStringExtra(Intent.ExtraPhoneNumber);
    string stateStr = intent.Extras.GetString(TelephonyManager.ExtraState);

       if (stateStr!=null)
       {
           if (stateStr.Equals(TelephonyManager.ExtraStateOffhook))
           { }
           else if (stateStr.Equals(TelephonyManager.ExtraStateIdle))
           { }
        }
     }
}

并使用此代码以下权限:

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

还有 AndroidManifest.xml

上的此接收器
<receiver android:name="OutgoingBroadcastReceiver" android:enabled="true" android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE_CHANGED" />
        </intent-filter>
    </receiver>

但只有在拨出电话开始或结束时才会触发。 请帮助我!!

0 个答案:

没有答案