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