本文整理汇总了Java中android.bluetooth.BluetoothHeadset类的典型用法代码示例。如果您正苦于以下问题:Java BluetoothHeadset类的具体用法?Java BluetoothHeadset怎么用?Java BluetoothHeadset使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BluetoothHeadset类属于android.bluetooth包,在下文中一共展示了BluetoothHeadset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: optional
import android.bluetooth.BluetoothHeadset; //导入依赖的package包/类
private void optional() {
HeadsetPlugManager.getInstance().registerHeadsetPlugListener(this);
mHeadsetListener = new HeadsetBroadcastReceiver();
registerReceiver(mHeadsetListener, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
mBluetoothHeadsetBroadcastListener = new BluetoothHeadsetBroadcastReceiver();
mBtAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBtAdapter != null && BluetoothProfile.STATE_CONNECTED == mBtAdapter.getProfileConnectionState(BluetoothProfile.HEADSET)) {
// on some devices, BT is not supported
boolean bt = mBtAdapter.getProfileProxy(getBaseContext(), mBluetoothHeadsetListener, BluetoothProfile.HEADSET);
int connection = mBtAdapter.getProfileConnectionState(BluetoothProfile.HEADSET);
}
IntentFilter i = new IntentFilter(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
i.addAction(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
i.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
registerReceiver(mBluetoothHeadsetBroadcastListener, i);
//避免对window添加ui修改参数
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
}
示例2: initBluetooth
import android.bluetooth.BluetoothHeadset; //导入依赖的package包/类
public void initBluetooth() {
if (!ensureInit()) {
Log.w("[Bluetooth] Manager tried to init bluetooth but LinphoneService not ready yet...");
return;
}
IntentFilter filter = new IntentFilter();
filter.addCategory(BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY + "." + BluetoothAssignedNumbers.PLANTRONICS);
filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
filter.addAction(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT);
mContext.registerReceiver(this, filter);
Log.d("[Bluetooth] Receiver started");
startBluetooth();
}
示例3: startBluetooth
import android.bluetooth.BluetoothHeadset; //导入依赖的package包/类
private void startBluetooth() {
if (isBluetoothConnected) {
Log.e("[Bluetooth] Already started, skipping...");
return;
}
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()) {
if (mProfileListener != null) {
Log.w("[Bluetooth] Headset profile was already opened, let's close it");
mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
}
mProfileListener = new BluetoothProfile.ServiceListener() {
public void onServiceConnected(int profile, BluetoothProfile proxy) {
if (profile == BluetoothProfile.HEADSET) {
Log.d("[Bluetooth] Headset connected");
mBluetoothHeadset = (BluetoothHeadset) proxy;
isBluetoothConnected = true;
}
}
public void onServiceDisconnected(int profile) {
if (profile == BluetoothProfile.HEADSET) {
mBluetoothHeadset = null;
isBluetoothConnected = false;
Log.d("[Bluetooth] Headset disconnected");
LinphoneManager.getInstance().routeAudioToReceiver();
}
}
};
boolean success = mBluetoothAdapter.getProfileProxy(mContext, mProfileListener, BluetoothProfile.HEADSET);
if (!success) {
Log.e("[Bluetooth] getProfileProxy failed !");
}
} else {
Log.w("[Bluetooth] Interface disabled on device");
}
}
示例4: isBluetoothHeadsetAvailable
import android.bluetooth.BluetoothHeadset; //导入依赖的package包/类
public boolean isBluetoothHeadsetAvailable() {
ensureInit();
if (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled() && mAudioManager != null && mAudioManager.isBluetoothScoAvailableOffCall()) {
boolean isHeadsetConnected = false;
if (mBluetoothHeadset != null) {
List<BluetoothDevice> devices = mBluetoothHeadset.getConnectedDevices();
mBluetoothDevice = null;
for (final BluetoothDevice dev : devices) {
if (mBluetoothHeadset.getConnectionState(dev) == BluetoothHeadset.STATE_CONNECTED) {
mBluetoothDevice = dev;
isHeadsetConnected = true;
break;
}
}
Log.d(isHeadsetConnected ? "[Bluetooth] Headset found, bluetooth audio route available" : "[Bluetooth] No headset found, bluetooth audio route unavailable");
}
return isHeadsetConnected;
}
return false;
}
示例5: BluetoothStateManager
import android.bluetooth.BluetoothHeadset; //导入依赖的package包/类
public BluetoothStateManager(@NonNull Context context, @Nullable BluetoothStateListener listener) {
this.context = context.getApplicationContext();
this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
this.bluetoothScoReceiver = new BluetoothScoReceiver();
this.bluetoothConnectionReceiver = new BluetoothConnectionReceiver();
this.listener = listener;
requestHeadsetProxyProfile();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
context.registerReceiver(bluetoothConnectionReceiver, new IntentFilter(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED));
}
Intent sticky = context.registerReceiver(bluetoothScoReceiver, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED));
if (sticky != null) {
bluetoothScoReceiver.onReceive(context, sticky);
}
handleBluetoothStateChange();
}
示例6: BluetoothStateManager
import android.bluetooth.BluetoothHeadset; //导入依赖的package包/类
public BluetoothStateManager(@NonNull Context context, @Nullable BluetoothStateListener listener) {
this.context = context.getApplicationContext();
this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
this.bluetoothScoReceiver = new BluetoothScoReceiver();
this.bluetoothConnectionReceiver = new BluetoothConnectionReceiver();
this.listener = listener;
if (this.bluetoothAdapter == null)
return;
requestHeadsetProxyProfile();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
context.registerReceiver(bluetoothConnectionReceiver, new IntentFilter(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED));
}
Intent sticky = context.registerReceiver(bluetoothScoReceiver, new IntentFilter(getScoChangeIntent()));
if (sticky != null) {
bluetoothScoReceiver.onReceive(context, sticky);
}
handleBluetoothStateChange();
}
示例7: onServiceConnected
import android.bluetooth.BluetoothHeadset; //导入依赖的package包/类
public void onServiceConnected(int profile, BluetoothProfile proxy) {
if (profile == BluetoothProfile.HEADSET) {
mBluetoothHeadset = (BluetoothHeadset) proxy;
List<BluetoothDevice> pairedDevices = mBluetoothHeadset.getConnectedDevices();
// If there are paired devices
if (pairedDevices.size() > 0) {
startSCO();
for (BluetoothDevice device : pairedDevices) {
Log.e(TAG, "BT Device :"+device.getName()+ " , BD_ADDR:" + device.getAddress()); //Print out Headset name
}
} else {
Toast.makeText(mContext, "Could not find a connected Headset, please connect a headset", Toast.LENGTH_LONG).show();
return;
}
}
}
示例8: onReceive
import android.bluetooth.BluetoothHeadset; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (ACTION_HEADSET_PLUG.equals(intent.getAction())) {
isHeadsetPlugged = intent.getIntExtra("state", 0) == 1;
if (isHeadsetPlugged && proximityWakelock != null && proximityWakelock.isHeld()) {
proximityWakelock.release();
}
isProximityNear = false;
updateOutputGainControlState();
} else if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
updateNetworkType();
} else if(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())){
//FileLog.e("bt headset state = "+intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0));
updateBluetoothHeadsetState(intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0)==BluetoothProfile.STATE_CONNECTED);
}else if(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED.equals(intent.getAction())){
for (StateListener l : stateListeners)
l.onAudioSettingsChanged();
}else if(TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(intent.getAction())){
String state=intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if(TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)){
hangUp();
}
}
}
示例9: onServiceConnected
import android.bluetooth.BluetoothHeadset; //导入依赖的package包/类
@Override
public void onServiceConnected(int profile, BluetoothProfile proxy) {
Log.e("blueHeadsetListener", "onServiceConnected:" + profile);
if (profile == BluetoothProfile.A2DP) {
voiceMediator.setBluetoothA2dp((BluetoothA2dp) proxy);
} else if (profile == BluetoothProfile.HEADSET) {
voiceMediator.setBluetoothHeadset((BluetoothHeadset) proxy);
}
}
示例10: startBluetoothSco
import android.bluetooth.BluetoothHeadset; //导入依赖的package包/类
@Override
public void startBluetoothSco() {
if (isBlueToothHeadSet()) {
BluetoothHeadset headset = getBluetoothHeadset();
if (headset == null || headset.getConnectedDevices().isEmpty() || headset.isAudioConnected(headset.getConnectedDevices().get(0)))
return;
Log.e(TAG, "startBluetoothSco:device size=" + headset.getConnectedDevices().size());
headset.startVoiceRecognition(headset.getConnectedDevices().get(0));
}
}
示例11: onServiceConnected
import android.bluetooth.BluetoothHeadset; //导入依赖的package包/类
@Override
// Called to notify the client when the proxy object has been connected to the service.
// Once we have the profile proxy object, we can use it to monitor the state of the
// connection and perform other operations that are relevant to the headset profile.
public void onServiceConnected(int profile, BluetoothProfile proxy) {
if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) {
return;
}
Log.d(TAG, "BluetoothServiceListener.onServiceConnected: BT state=" + bluetoothState);
// Android only supports one connected Bluetooth Headset at a time.
bluetoothHeadset = (BluetoothHeadset) proxy;
updateAudioDeviceState();
Log.d(TAG, "onServiceConnected done: BT state=" + bluetoothState);
}
示例12: onReceive
import android.bluetooth.BluetoothHeadset; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
BluetoothDevice mConnectedHeadset = null;
String action = intent.getAction();
int state = BluetoothHeadset.STATE_DISCONNECTED;
int previousState = intent.getIntExtra(BluetoothHeadset.EXTRA_PREVIOUS_STATE, BluetoothHeadset.STATE_DISCONNECTED);
if (BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
state = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE, BluetoothHeadset.STATE_DISCONNECTED);
if (state == BluetoothHeadset.STATE_CONNECTED) {
mConnectedHeadset = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
log.debug("AudioManager ACTION_CONNECTION_STATE_CHANGED " + mConnectedHeadset + " " + state);
HeadsetPlugManager.getInstance().notifyHeadsetPlugged(true, HeadsetPlugManager.BLUETOOTH, mConnectedHeadset);
} else if (state == BluetoothHeadset.STATE_DISCONNECTED) {
mConnectedHeadset = null;
log.debug("AudioManager ACTION_CONNECTION_STATE_CHANGED " + " " + state);
HeadsetPlugManager.getInstance().notifyHeadsetPlugged(false, HeadsetPlugManager.BLUETOOTH);
}
} else if (BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED.equals(action)) {
state = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE, BluetoothHeadset.STATE_AUDIO_DISCONNECTED);
log.debug("AudioManager ACTION_AUDIO_STATE_CHANGED " + " " + state);
if (state == BluetoothHeadset.STATE_AUDIO_CONNECTED) {
// bluetooth audio connected. you send audio stream to headset now!!!
} else if (state == BluetoothHeadset.STATE_AUDIO_DISCONNECTED) {
}
} else if (AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED.equals(action)) {
state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, AudioManager.SCO_AUDIO_STATE_DISCONNECTED);
log.debug("AudioManager ACTION_SCO_AUDIO_STATE_UPDATED " + " " + state);
}
}
示例13: onServiceConnected
import android.bluetooth.BluetoothHeadset; //导入依赖的package包/类
@Override
// Called to notify the client when the proxy object has been connected to the service.
// Once we have the profile proxy object, we can use it to monitor the state of the
// connection and perform other operations that are relevant to the headset profile.
public void onServiceConnected(int profile, BluetoothProfile proxy) {
if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) {
return;
}
Log.d(TAG, "BluetoothServiceListener.onServiceConnected: BT state=" + bluetoothState);
// Android only supports one connected Bluetooth Headset at a time.
bluetoothHeadset = (BluetoothHeadset) proxy;
updateAudioDeviceState();
Log.d(TAG, "onServiceConnected done: BT state=" + bluetoothState);
}
示例14: onReceive
import android.bluetooth.BluetoothHeadset; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent)
{
int state = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE, BluetoothHeadset.STATE_DISCONNECTED);
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
editor.putBoolean(SETTING_HEADSET_CONNECTED, state == BluetoothHeadset.STATE_CONNECTED);
editor.apply();
}
示例15: onReceive
import android.bluetooth.BluetoothHeadset; //导入依赖的package包/类
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "BT state changed");
String action = intent.getAction();
if (BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
int status = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE, 0);
if (status == 2) {
Log.d(TAG, "BT device found");
// Discovery has found a device. Get the BluetoothDevice
// object and its info from the Intent.
if (btChangesListener != null) {
btChangesListener.onBluetoothStateChanged(status);
}
}
}
}