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

cancel outgoing call with default dialer app

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

来电、接听、挂断都很好 android.telecom

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

知道如何取消通过手机拨打的电话吗?

您可以使用 TelecomManager class 来切断通话。

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>