本文整理匯總了Java中android.bluetooth.BluetoothProfile.HEADSET屬性的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothProfile.HEADSET屬性的具體用法?Java BluetoothProfile.HEADSET怎麽用?Java BluetoothProfile.HEADSET使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.bluetooth.BluetoothProfile
的用法示例。
在下文中一共展示了BluetoothProfile.HEADSET屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: startBluetooth
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");
}
}
示例2: onServiceDisconnected
@Override
public void onServiceDisconnected(int profile) {
Log.e("blueHeadsetListener", "onServiceDisconnected:" + profile);
if (profile == BluetoothProfile.A2DP) {
voiceMediator.setBluetoothA2dp(null);
} else if (profile == BluetoothProfile.HEADSET) {
voiceMediator.setBluetoothHeadset(null);
}
}
示例3: onServiceConnected
@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);
}
}
示例4: onServiceConnected
@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);
}
示例5: onServiceDisconnected
@Override
/** Notifies the client when the proxy object has been disconnected from the service. */
public void onServiceDisconnected(int profile) {
if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) {
return;
}
Log.d(TAG, "BluetoothServiceListener.onServiceDisconnected: BT state=" + bluetoothState);
stopScoAudio();
bluetoothHeadset = null;
bluetoothDevice = null;
bluetoothState = State.HEADSET_UNAVAILABLE;
updateAudioDeviceState();
Log.d(TAG, "onServiceDisconnected done: BT state=" + bluetoothState);
}
示例6: onServiceConnected
/**
* 監聽到藍牙設備連接
* @param profile
* @param headset
*/
@Override
public void onServiceConnected(int profile, BluetoothProfile headset) {
if (profile == BluetoothProfile.HEADSET) {
LogUtil.e("onServiceConnected " + profile + " " + headset);
mBluetoothProfile = headset;
List<BluetoothDevice> devices = headset.getConnectedDevices();
headsetPlugged(devices != null && devices.size() > 0);
}
}
示例7: onServiceConnected
@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);
}
示例8: onServiceDisconnected
@Override
/** Notifies the client when the proxy object has been disconnected from the service. */
public void onServiceDisconnected(int profile) {
if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) {
return;
}
Log.d(TAG, "BluetoothServiceListener.onServiceDisconnected: BT state=" + bluetoothState);
stopScoAudio();
bluetoothHeadset = null;
bluetoothDevice = null;
bluetoothState = State.HEADSET_UNAVAILABLE;
updateAudioDeviceState();
Log.d(TAG, "onServiceDisconnected done: BT state=" + bluetoothState);
}
示例9: onServiceConnected
@Override
public void onServiceConnected(int profile, BluetoothProfile proxy) {
try {
if (profile == BluetoothProfile.HEADSET) {
// bh = (BluetoothHeadset) proxy;
// if (bh.getConnectionState(mTouchObject.bluetoothDevice) != BluetoothProfile.STATE_CONNECTED){
// bh.getClass()
// .getMethod("connect", BluetoothDevice.class)
// .invoke(bh, mTouchObject.bluetoothDevice);
// }
} else if (profile == BluetoothProfile.A2DP) {
/**使用A2DP的協議連接藍牙設備(使用了反射技術調用連接的方法)*/
a2dp = (BluetoothA2dp) proxy;
if (a2dp.getConnectionState(currentBluetoothDevice) != BluetoothProfile.STATE_CONNECTED) {
a2dp.getClass()
.getMethod("connect", BluetoothDevice.class)
.invoke(a2dp, currentBluetoothDevice);
Toast.makeText(MainActivity.this,"請播放音樂",Toast.LENGTH_SHORT).show();
getBondedDevices();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例10: setUp
@Before
public void setUp() {
ShadowLog.stream = System.out;
context = ShadowApplication.getInstance().getApplicationContext();
mockedAppRtcAudioManager = mock(AppRTCAudioManager.class);
mockedAudioManager = mock(AudioManager.class);
mockedBluetoothHeadset = mock(BluetoothHeadset.class);
mockedBluetoothDevice = mock(BluetoothDevice.class);
mockedBluetoothDeviceList = new LinkedList<BluetoothDevice>();
// Simulate that bluetooth SCO audio is available by default.
when(mockedAudioManager.isBluetoothScoAvailableOffCall()).thenReturn(true);
// Create the test object and override protected methods for this test.
bluetoothManager = new AppRTCBluetoothManager(context, mockedAppRtcAudioManager) {
@Override
protected AudioManager getAudioManager(Context context) {
Log.d(TAG, "getAudioManager");
return mockedAudioManager;
}
@Override
protected void registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
Log.d(TAG, "registerReceiver");
if (filter.hasAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)
&& filter.hasAction(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED)) {
// Gives access to the real broadcast receiver so the test can use it.
bluetoothHeadsetStateReceiver = receiver;
}
}
@Override
protected void unregisterReceiver(BroadcastReceiver receiver) {
Log.d(TAG, "unregisterReceiver");
if (receiver == bluetoothHeadsetStateReceiver) {
bluetoothHeadsetStateReceiver = null;
}
}
@Override
protected boolean getBluetoothProfileProxy(
Context context, BluetoothProfile.ServiceListener listener, int profile) {
Log.d(TAG, "getBluetoothProfileProxy");
if (profile == BluetoothProfile.HEADSET) {
// Allows the test to access the real Bluetooth service listener object.
bluetoothServiceListener = listener;
}
return true;
}
@Override
protected boolean hasPermission(Context context, String permission) {
Log.d(TAG, "hasPermission(" + permission + ")");
// Ensure that the client asks for Bluetooth permission.
return (permission == android.Manifest.permission.BLUETOOTH);
}
@Override
protected void logBluetoothAdapterInfo(BluetoothAdapter localAdapter) {
// Do nothing in tests. No need to mock BluetoothAdapter.
}
};
}
示例11: getProfileCode
@Override
public int getProfileCode() {
return BluetoothProfile.HEADSET;
}