Android 如何从Call.Callback和InCallService TelecomManager获取呼叫事件?

Android 如何从Call.Callback和InCallService TelecomManager获取呼叫事件?,android,Android,我在Android应用程序中工作,我想处理一些电话呼叫事件 我不喜欢为了打电话而替换当前的UI,只是为了处理通话进程中的事件。我已经使用了PhoneStateListener,但只有三种状态:CALL\u STATE\u IDLE、CALL\u STATE\u OFFHOOK、CALL\u STATE\u RINGING 我想有权访问 我现在不知道如何从我的活动绑定InCallService。这里有一些代码来理解我想做什么 MyService类 public class MyService ex

我在Android应用程序中工作,我想处理一些电话呼叫事件

我不喜欢为了打电话而替换当前的UI,只是为了处理通话进程中的事件。我已经使用了PhoneStateListener,但只有三种状态:CALL\u STATE\u IDLE、CALL\u STATE\u OFFHOOK、CALL\u STATE\u RINGING

我想有权访问

我现在不知道如何从我的活动绑定InCallService。这里有一些代码来理解我想做什么

MyService类

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的助手类

从我的活动开始,我开始服务:

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是拨号程序/电话应用程序用于为正在进行的电话呼叫实现incall UI的API。目前没有办法让系统绑定到InCallService实现,除非用户选择它作为默认拨号程序。

这段代码有效吗?你想要的是显示活动的值?我只想处理调用事件。当一个呼叫开始和结束时,我呼叫结束的原因来自用户正常,没有信号,用户从未接听,用户拒绝来电。我这段代码我无法访问InCallService.TelecomManager.getDefaultDialerPackage在执行服务之前尝试在Main活动中调用此函数我已经这样做了你知道3年后情况是否仍然如此吗?@j2emanue,InCallService API对默认拨号程序和,从Android S开始,它将通过CompanyDeviceManager API提供给手表伴侣应用程序。
 <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>