android - 如何从 Call.Callback 和 InCallService TelecomManager 获取呼叫事件?
问题描述
我正在使用 Android 应用程序,我想处理一些电话呼叫事件。
我不喜欢替换当前的 UI 来拨打电话,只是为了处理通话进度的事件。我已经使用 PhoneStateListener 但只有 3 个状态(CALL_STATE_IDLE、CALL_STATE_OFFHOOK、CALL_STATE_RINGING)。
我想访问Call.Details 之类的DisconnectCause
我现在不知道如何从我的 Activity 绑定 InCallService。这是一些代码来理解我想要做什么。
我的服务类
public class MyService extends InCallService {
public static final String TAG = "MyService";
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
Log.d(TAG, "On Start");
return START_STICKY;
}
@Override
public void onCallAdded(Call call) {
super.onCallAdded(call);
call.registerCallback(new CallbackTelecomHelper(this));
Log.d(TAG, "onCallAdded");
Log.d(TAG, "onCallAdded details" + call.getDetails());
}
@Override
public void onCallRemoved(Call call) {
super.onCallRemoved(call);
Log.d(TAG, "onCallRemoved");
Log.d(TAG, "onCallRemoved details" + call.getDetails());
}
@Override
public void onConnectionEvent(Call call, String event, Bundle extras) {
super.onConnectionEvent(call, event, extras);
Log.d(TAG, "getDisconnect code: " + call.getDetails().getDisconnectCause().getCode());
Log.d(TAG, "getDisconnect reason: " + call.getDetails().getDisconnectCause().getReason());
Log.d(TAG, "getDisconnect description: " + call.getDetails().getDisconnectCause().getDescription());
Log.d(TAG, "event : " + event);
}
CallbackTelecomHelper - Call.Callback的帮助器类
public class CallbackTelecomHelper extends Call.Callback {
String TAG = "CallbackTelecomHelper_TAG";
private Context context;
public CallbackTelecomHelper(Context context){
this.context = context;
}
@Override
public void onStateChanged(Call call, int state) {
super.onStateChanged(call, state);
Log.i(TAG, "onStateChanged");
}
@Override
public void onDetailsChanged(Call call, Call.Details details) {
super.onDetailsChanged(call, details);
Log.i(TAG, "onDetailsChanged");
}
@Override
public void onCallDestroyed(Call call) {
super.onCallDestroyed(call);
Log.i(TAG, "onCallDestroyed");
}
@Override
public void onConnectionEvent(Call call, String event, Bundle extras) {
super.onConnectionEvent(call, event, extras);
Log.i(TAG, "onConnectionEvent");
}
@Override
public void onRttRequest(Call call, int id) {
super.onRttRequest(call, id);
Log.i(TAG, "onRttRequest");
}
从我的活动我开始服务:
TelecomManager telecomManager = (TelecomManager) getSystemService(TELECOM_SERVICE);
telecomManager.getDefaultDialerPackage();
Intent intentConnection = new Intent(this, MyService.class);
startService(intentConnection);
清单设置:
<activity
android:name=".ui.ScenarioMapActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service android:name=".services.Connection.MyService"
android:permission="android.permission.BIND_INCALL_SERVICE">
<meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
<intent-filter>
<action android:name="android.telecom.InCallService"/>
</intent-filter>
</service>
知道如何访问这些信息吗?对不起我的英语不好!
解决方案
InCallService API 是 Dialer/Phone 应用程序用来为正在进行的电话实现 incall UI 的。目前没有办法让系统绑定到 InCallService 实现,除非用户选择它作为默认拨号程序。
推荐阅读
- c# - 在 DevExp 上更改 gridView 上的单元格数据
- cloudera-manager - Cloudera Manager [用尽可用的身份验证方法]
- c# - 如何正确清理 TcpListener,以避免“地址已在使用”错误?
- ios - 如何获取 N 个最近的项目,但使用 NSFetchRequest 按升序对它们进行排序
- html - 如何从中心用虚线连接圆圈?
- azure - 从 api 管理获取 Azure Key Vault 中的机密?
- c# - 正则表达式模式 c#
- python - 在 ubuntu linux 和 windows 中显示不同的情节
- c# - 在客户端 PC 上安装 Windows 安装程序包 (.msi) 的要求
- sql - 如何将 SELECT 查询的结果表存储在变量中?