使用默认拨号器应用程序取消拨出电话



我有一个应用程序成为默认拨号器。

它通过使用android.telecom类很好地处理来电、接听和挂断

现在我要做的是,当蓝牙手机拨打一个号码时,停止该拨号,并使用相同的号码启动whatsapp拨号uri。

知道如何取消通过手机拨打的呼叫吗?

您可以使用

TelecomManager类来切断呼叫。

TelecomManager telecomManager = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
if (telecomManager != null) {
if(telecomManager .endCall())
Toast(mContext,"Call ended",Toast.LENGTH_SHORT).show();
else
Toast(mContext,"Failed to end the call",Toast.LENGTH_SHORT).show();
}

您需要权限

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

接收方权限

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

广播接收器

public class OutgoingCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Log.d(OutgoingCallReceiver.class.getSimpleName(), intent.toString());
    Toast.makeText(context, "Outgoing call happening!", Toast.LENGTH_LONG).show();
 // cancel your call here    }
}

更新清单

<receiver  android:name=".OutGoingCallReceiver" 
android:exported="true"> 
<intent-filter>   
<action
android:name="android.intent.action.NEW_OUTGOING_CALL"
android:priority="0" /> 
</intent-filter> 
</receiver>

最新更新