我有一个应用程序,成为默认拨号器。
它适用于来电,通过使用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>