CarAppFocusManager使用

CarAppFocusManager是android.car.jar中的类,用于管理车机系统的应用焦点,如导航或语音命令的激活状态。它确保系统中通常只运行一个此类应用实例,并能处理音频焦点的设置和监听,实现应用间的互斥操作。
摘要由CSDN通过智能技术生成

CarAppFocusManager

位于android.car.jar中。

官方介绍

CarAppFocusManager allows applications to set and listen for the current application focus like active navigation or active voice command. Usually only one instance of such application should run in the system, and other app setting the flag for the matching app should lead into other app to stop.

主要是为了处理车机系统中音频焦点的管理和互斥操作。

使用

public class ECAudioFocusManager {

    private Car mCar;
    private CarAudioManager mCarAudioManager = null;

    private AudioFocusListener audioFocusListener = null;

    private CarAppFocusManager mAppFocusManager;
    private AppFocusOwnershipCallback mAppFocusCallback;

    ECAudioFocusManager() {
        mCar = Car.createCar(ECManager.getInstance().getContext(), new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
                try {
                    mCarAudioManager = (CarAudioManager) mCar.getCarManager(Car.AUDIO_SERVICE);
                } catch (CarNotConnectedException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {

            }
        });
        mCar.connect();
		
        audioFocusListener = new AudioFocusListener();

        if (mCar.isConnected()) {
            AppFocusChangedListener mListener = new AppFocusChangedListener();
            mAppFocusCallback = new AppFocusOwnershipCallback();
            try {
                mAppFocusManager = (CarAppFocusManager) mCar.getCarManager(Car.APP_F
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值