mtk android 11接打电话默认免提功能

这篇博客介绍了如何在MTK源码中实现通话免提功能。首先,在device.mk文件中启用MTK_TB_APP_CALL_FORCE_SPEAKER_ON宏来控制通话免提。然后,提供了两种方法进行修改:一种是在InCallService.java中监听电话状态并设置音频路由;另一种是在Engine.cpp中调整音频策略,强制使用扬声器。这些修改确保了拨打和接听电话时都能使用免提功能。
摘要由CSDN通过智能技术生成

修改功能的方案为MTK的源码,其他方案源码仅供参考。

1.在mtk源码当中有专门的宏控进行开关一些功能,就像这次的打电话面提功能。在device.mk文件当中可以搜到这个MTK_TB_APP_CALL_FORCE_SPEAKER_ON,当它为yes的时候通话免提只是拨打的时候免提,接听的时候并不是免提状态。

--- a/alps/device/mediateksample/xx/ProjectConfig.mk
+++ b/alps/device/mediateksample/xx/ProjectConfig.mk
@@ -539,6 +539,7 @@ MTK_SMART_CHARGING = no
 MTK_ADSP_VA_SUPPORT = no
 MTK_CAM_BSS_SUPPORT = 0
 MTK_LK_VERSION = lk
+MTK_TB_APP_CALL_FORCE_SPEAKER_ON=yes

2.因接听的时候并不是免提状态,所以有以下修改。

第一种方法:

--- a/alps/frameworks/base/telecomm/java/android/telecom/InCallService.java
+++ b/alps/frameworks/base/telecomm/java/android/telecom/InCallService.java
@@ -40,6 +40,10 @@ import com.android.internal.telecom.IInCallService;
 import java.util.Collections;
 import java.util.List;
 
+import android.telecom.CallAudioState;
+import android.telephony.PhoneStateListener;
+import android.telephony.TelephonyManager;
+import android.content.Context;
 /**
  * This service is implemented by an app that wishes to provide functionality for managing
  * phone calls.
@@ -230,6 +234,40 @@ public abstract class InCallService extends Service {
     private static final int MSG_ON_HANDOVER_FAILED = 12;
     private static final int MSG_ON_HANDOVER_COMPLETE = 13;
 
+       //Added by lwz start 
+       @Override
+         public void onCreate() {
+                super.onCreate();
+               MyPhoneStateListener phonehoneStateListener=new MyPhoneStateListener();
+               TelephonyManager mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
+               mTelephonyManager.listen(phonehoneStateListener,PhoneStateListener.LISTEN_CALL_STATE);
+         }
+         
+               @Override
+         public void onDestroy() {
+               super.onDestroy();
+         }
+         
+          private class MyPhoneStateListener extends PhoneStateListener{
+               @Override
+               public void onCallStateChanged(int state, String incomingNumber) {
+                 switch (state) {
+                 case TelephonyManager.CALL_STATE_IDLE:
+                   setAudioRoute(CallAudioState.ROUTE_EARPIECE);
+                   break;
+                 case TelephonyManager.CALL_STATE_RINGING:
+                   setAudioRoute(CallAudioState.ROUTE_SPEAKER);
+                   break;
+                 case TelephonyManager.CALL_STATE_OFFHOOK:
+                 setAudioRoute(CallAudioState.ROUTE_SPEAKER);
+                 default:
+                   break;
+                 }
+                 super.onCallStateChanged(state, incomingNumber);
+               }
+         }
+       //Added by lwz end
+       
     /** Default Handler used to consolidate binder method calls onto a single thread. */
     private final Handler mHandler = new Handler(Looper.getMainLooper()) {
         @Override

第二种方法:

index fe2a32b..101b15c 100644
--- a/alps/frameworks/av/services/audiopolicy/enginedefault/src/Engine.cpp
+++ b/alps/frameworks/av/services/audiopolicy/enginedefault/src/Engine.cpp
@@ -295,7 +295,8 @@ DeviceVector Engine::getDevicesForStrategyInt(legacy_strategy strategy,
                         AUDIO_DEVICE_OUT_AUX_DIGITAL, AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET});
                 if (!devices.isEmpty()) break;
             }
-            devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_EARPIECE);
+            //devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_EARPIECE);
+            devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_SPEAKER);
             break;
 
         case AUDIO_POLICY_FORCE_SPEAKER:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值