本文整理汇总了Java中android.bluetooth.BluetoothProfile类的典型用法代码示例。如果您正苦于以下问题:Java BluetoothProfile类的具体用法?Java BluetoothProfile怎么用?Java BluetoothProfile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BluetoothProfile类属于android.bluetooth包,在下文中一共展示了BluetoothProfile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: optional
import android.bluetooth.BluetoothProfile; //导入依赖的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: onConnectionStateChange
import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_CONNECTED;
connectionState = STATE_CONNECTED;
broadcastUpdate(intentAction);
Log.i(TAG, "Connected to GATT server.");
Log.i(TAG, "Attempting to start service discovery:" + bluetoothGatt.discoverServices());
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
intentAction = ACTION_DISCONNECTED;
connectionState = STATE_DISCONNECTED;
Log.i(TAG, "Disconnected from GATT server.");
broadcastUpdate(intentAction);
}
}
示例3: startBluetooth
import android.bluetooth.BluetoothProfile; //导入依赖的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: stopBluetooth
import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
public void stopBluetooth() {
Log.w("[Bluetooth] Stopping...");
isBluetoothConnected = false;
disableBluetoothSCO();
if (mBluetoothAdapter != null && mProfileListener != null && mBluetoothHeadset != null) {
mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
mProfileListener = null;
}
mBluetoothDevice = null;
Log.w("[Bluetooth] Stopped!");
if (LinphoneManager.isInstanciated()) {
LinphoneManager.getInstance().routeAudioToReceiver();
}
}
示例5: onConnectionStateChange
import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
Log.d("BLUETOOTH", "Estado de conexión bluetooth: " + (newState == BluetoothProfile.STATE_CONNECTED ? "Connected" : "Disconnected"));
if(newState == BluetoothProfile.STATE_CONNECTED){
//setState(State.CONNECTED);
mBluetoothGatt.discoverServices();
}
else{
//setState(State.IDDLE);
//TODO Realizar todas las tareas necesarias cuando se desconecte la pulsera
Log.d("BLUETOOTH", "Se ha desconectado el dispostivo bluetooth");
}
}
示例6: onConnectionStateChange
import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
if (newState == BluetoothProfile.STATE_CONNECTED) {
connected = true;
gatt.discoverServices();
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
connected = false;
btGatt.close();
btGatt = null;
charSerial = null;
messenger.obtainMessage(MessageConstants.STATUS, StatusCode.Disconnected).sendToTarget();
} else {
messenger.obtainMessage(MessageConstants.ERROR, ErrorCode.Connect).sendToTarget();
taskConnectTimeout.cancel();
}
}
示例7: stop
import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
/**
* Stops and closes all components related to Bluetooth audio.
*/
public void stop() {
ThreadUtils.checkIsOnMainThread();
Log.d(TAG, "stop: BT state=" + bluetoothState);
if (bluetoothAdapter == null) {
return;
}
// Stop BT SCO connection with remote device if needed.
stopScoAudio();
// Close down remaining BT resources.
if (bluetoothState == State.UNINITIALIZED) {
return;
}
unregisterReceiver(bluetoothHeadsetReceiver);
cancelTimer();
if (bluetoothHeadset != null) {
bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, bluetoothHeadset);
bluetoothHeadset = null;
}
bluetoothAdapter = null;
bluetoothDevice = null;
bluetoothState = State.UNINITIALIZED;
Log.d(TAG, "stop done: BT state=" + bluetoothState);
}
示例8: optionalDestroy
import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
private void optionalDestroy() {
if (mBtAdapter != null) {
mBtAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothProfile);
mBluetoothProfile = null;
mBtAdapter = null;
}
if (mBluetoothHeadsetBroadcastListener != null) {
unregisterReceiver(mBluetoothHeadsetBroadcastListener);
mBluetoothHeadsetBroadcastListener = null;
}
if (mHeadsetListener != null) {
unregisterReceiver(mHeadsetListener);
mHeadsetListener = null;
}
HeadsetPlugManager.getInstance().unregisterHeadsetPlugListener(this);
}
示例9: onConnectionStateChange
import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
if(mOnConnectListener!=null)
mOnConnectListener.onConnect(gatt);
Log.i(TAG, "Connected to GATT server.");
// Attempts to discover services after successful connection.
Log.i(TAG, "Attempting to start service discovery:" +
mBluetoothGatt.discoverServices());
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
if(mOnDisconnectListener!=null)
mOnDisconnectListener.onDisconnect(gatt);
Log.i(TAG, "Disconnected from GATT server.");
}
if(mOnConnectStatusChangedListener!=null)
mOnConnectStatusChangedListener.onConnectStatusChanged(gatt,status,newState);
Log.i(TAG, "Changed");
}
示例10: onConnectionStateChange
import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
/**
* Callback indicating when GATT client has connected/disconnected to/from a remote
* GATT server.
*
* @param gatt GATT client
* @param status Status of the connect or disconnect operation.
* {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
* @param newState Returns the new connection state. Can be one of
* {@link android.bluetooth.BluetoothProfile#STATE_DISCONNECTED} or
* {@link android.bluetooth.BluetoothProfile#STATE_CONNECTED}
*/
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
// boolean indicating whether or not the next step is successful, default is false
boolean success = false;
// Start Service discovery if we're now connected
if (status == BluetoothGatt.GATT_SUCCESS) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
success = gatt.discoverServices();
} // else: not connected, continue
} // else: not successful
onStep(gatt, success);
}
示例11: onCreate
import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
/**
* Make sure Bluetooth and health profile are available on the Android device. Stop service
* if they are not available.
*/
@Override
public void onCreate() {
super.onCreate();
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
// Bluetooth adapter isn't available. The client of the service is supposed to
// verify that it is available and activate before invoking this service.
stopSelf();
return;
}
if (!mBluetoothAdapter.getProfileProxy(this, mBluetoothServiceListener,
BluetoothProfile.HEALTH)) {
Toast.makeText(this, R.string.bluetooth_health_profile_not_available,
Toast.LENGTH_LONG);
stopSelf();
return;
}
}
示例12: onConnectionStateChange
import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_CONNECTED;
mConnectionState = STATE_CONNECTED;
broadcastUpdate(intentAction);
Log.i(TAG, "Connected to GATT server.");
// Attempts to discover services after successful connection.
Log.i(TAG, "Attempting to start service discovery:" +
mBluetoothGatt.discoverServices());
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
intentAction = ACTION_GATT_DISCONNECTED;
mConnectionState = STATE_DISCONNECTED;
Log.i(TAG, "Disconnected from GATT server.");
broadcastUpdate(intentAction);
}
}
示例13: stop
import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
/** Stops and closes all components related to Bluetooth audio. */
public void stop() {
ThreadUtils.checkIsOnMainThread();
Log.d(TAG, "stop: BT state=" + bluetoothState);
if (bluetoothAdapter == null) {
return;
}
// Stop BT SCO connection with remote device if needed.
stopScoAudio();
// Close down remaining BT resources.
if (bluetoothState == State.UNINITIALIZED) {
return;
}
unregisterReceiver(bluetoothHeadsetReceiver);
cancelTimer();
if (bluetoothHeadset != null) {
bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, bluetoothHeadset);
bluetoothHeadset = null;
}
bluetoothAdapter = null;
bluetoothDevice = null;
bluetoothState = State.UNINITIALIZED;
Log.d(TAG, "stop done: BT state=" + bluetoothState);
}
示例14: stop
import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
/**
* Stops and closes all components related to Bluetooth audio.
*/
public void stop() {
ThreadUtils.checkIsOnMainThread();
unregisterReceiver(bluetoothHeadsetReceiver);
Log.d(TAG, "stop: BT state=" + bluetoothState);
if (bluetoothAdapter != null) {
// Stop BT SCO connection with remote device if needed.
stopScoAudio();
// Close down remaining BT resources.
if (bluetoothState != State.UNINITIALIZED) {
cancelTimer();
if (bluetoothHeadset != null) {
bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, bluetoothHeadset);
bluetoothHeadset = null;
}
bluetoothAdapter = null;
bluetoothDevice = null;
bluetoothState = State.UNINITIALIZED;
}
}
Log.d(TAG, "stop done: BT state=" + bluetoothState);
}
示例15: onConnectionStateChange
import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) {
Log.i(TAG, "Connected to GATT server.");
if( gatt.getDevice().getBondState() != BluetoothDevice.BOND_BONDED ) {
broadcastUpdate(ACTION_NOT_PAIRED);
gatt.disconnect();
return;
}
Log.i(TAG, "Attempting to start service discovery" );
mBluetoothGatt.discoverServices();
connected = true;
broadcastUpdate(ACTION_GATT_CLIENT_CONNECTED);
}
else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
intentAction = ACTION_GATT_CLIENT_DISCONNECTED;
Log.i(TAG, "Disconnected from GATT server.");
broadcastUpdate(intentAction);
connected = false;
}
}