我正在使用Android应用程序,我想处理一些电话通话事件。

我不喜欢替换当前的UI来进行呼叫,而只是处理呼叫进度中的事件。我已经使用了PhoneStateListener,但是只有3种状态(CALL_STATE_IDLE,CALL_STATE_OFFHOOK,CALL_STATE_RINGING)。

我想像Call.Details一样访问DisconnectCause

我现在不怎么从我的活动中绑定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的帮助器类

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>


知道我如何获得这些信息吗?
对不起我的英语不好!

最佳答案

Dialer / Phone应用程序使用InCallService API来为正在进行的电话实现来电UI。当前没有一种方法可以使系统绑定到InCallService实现,除非用户已将其选择为默认拨号程序。

关于android - 如何从Call.Callback和InCallService TelecomManager获取调用事件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50796786/

10-09 01:28