本文整理匯總了Java中android.bluetooth.BluetoothProfile.STATE_CONNECTED屬性的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothProfile.STATE_CONNECTED屬性的具體用法?Java BluetoothProfile.STATE_CONNECTED怎麽用?Java BluetoothProfile.STATE_CONNECTED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.bluetooth.BluetoothProfile
的用法示例。
在下文中一共展示了BluetoothProfile.STATE_CONNECTED屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: optional
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
@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;
}
}
示例3: onConnectionStateChange
@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();
}
}
示例4: onConnectionStateChange
@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");
}
示例5: onConnectionStateChange
/**
* 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);
}
示例6: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
Log.e(TAG, "onConnectionStateChanged");
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) { // STATE : connected
intentAction = ACTION_GATT_CONNECTED;
mConnectionState = STATE_CONNECTED;
broadcastUpdate(intentAction); // broadcast Gatt connection state : connected
Log.e(TAG, "Connected to GATT server.");
Log.e(TAG, "Attempting to start service discovery:" + mBluetoothGatt.discoverServices());
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) { // STATE : disconnected
intentAction = ACTION_GATT_DISCONNECTED;
mConnectionState = STATE_DISCONNECTED;
broadcastUpdate(intentAction); // broadcast Gatt connection state : disconnected
Log.e(TAG, "Disconnected from GATT server.");
}
}
示例7: onConnectionStateChange
@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);
}
}
示例8: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_CONNECTED;
mConnectionState = STATE_CONNECTED;
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.");
}
}
示例9: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState)
{
mGatt = gatt;
switch(newState)
{
case BluetoothProfile.STATE_CONNECTED:
Log.d(TAG, "Gatt state: connected");
gatt.discoverServices();
mDeviceConnected = true;
if(mConnectionLatch != null)
{
mConnectionLatch.countDown();
}
break;
default:
Log.d(TAG, "Gatt state: not connected");
mDeviceConnected = false;
break;
}
}
示例10: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
Config.logi("BluetoothGatt connection State Changed: [" + status + "]" + newState);
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_CONNECTED;
mConnectionState = STATE_CONNECTED;
broadcastUpdate(intentAction, gatt.getDevice().getAddress());
Log.i(TAG, "Connected to GATT server.");
// Attempts to discover services after successful connection.
Log.i(TAG, "Attempting to startScan findService discovery:" +
gatt.discoverServices());
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
intentAction = ACTION_GATT_DISCONNECTED;
mConnectionState = STATE_DISCONNECTED;
gatt.close();//make 133 not fire.
Log.i(TAG, "Disconnected from GATT server.");
broadcastUpdate(intentAction, gatt.getDevice().getAddress());
}
}
示例11: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_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;
Log.i(TAG, "Disconnected from GATT server.");
broadcastUpdate(intentAction);
}
}
示例12: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
Log.d(TAG, "Connection State Change: " + status + " -> " + connectionState(newState));
if (status == BluetoothGatt.GATT_SUCCESS && newState == BluetoothProfile.STATE_CONNECTED) {
/*
* Once successfully connected, we must next discover all the services on the
* device before we can read and write their characteristics.
*/
gatt.discoverServices();
mHandler.sendMessage(Message.obtain(null, MSG_PROGRESS, "Discovering Services..."));
} else if (status == BluetoothGatt.GATT_SUCCESS && newState == BluetoothProfile.STATE_DISCONNECTED) {
/*
* If at any point we disconnect, send a message to clear the weather values
* out of the UI
*/
mHandler.sendEmptyMessage(MSG_CLEAR);
} else if (status != BluetoothGatt.GATT_SUCCESS) {
/*
* If there is a failure at any stage, simply disconnect
*/
gatt.disconnect();
}
}
示例13: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothDevice device, int status, int newState) {
if (mProvClientDev != null) {
if (mProvClientDev.getPeerDevice() != null) {
if (mProvClientDev.getPeerDevice().equals(device)) {
String strAddr = device.getAddress();
byte[] addr = stringToAddress(strAddr);
if (newState == BluetoothProfile.STATE_CONNECTED) {
if (mProvClientDev.getConnectionState() == PeerDevice.STATE_DISCONNECTED) {
mProvClientDev.setPeerDevice(device);
mProvClientDev.setConnectionState(PeerDevice.STATE_CONNECTED);
if (D) {
Log.i(TAG, "Connected to GATT Client.");
}
connectionChangedNative(addr, true, status);
}
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
mProvClientDev.setConnectionState(PeerDevice.STATE_DISCONNECTED);
if (D) {
Log.i(TAG, "Disconnected from GATT Client.");
}
advertiseStop();
connectionChangedNative(addr, false, status);
mGattServer.close();
}
}
}
}
}
示例14: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
Log.d(TAG, "BluetoothGattCallback.nConnectionStateChange: status=" + status + " newState=" + newState);
updateLog("Bluetooth connection state change: status="+ status + " newState=" + newState);
if (newState == BluetoothProfile.STATE_CONNECTED) {
gatt.discoverServices();
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
if (gatt.getDevice().getAddress().equals(mOWDevice.deviceMacAddress.get())) {
onOWStateChangedToDisconnected(gatt);
}
updateLog("--> Closed " + gatt.getDevice().getAddress());
Log.d(TAG, "Disconnect:" + gatt.getDevice().getAddress());
}
}
示例15: onConnectionStateChange
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
NLog.d("onConnectionStatusChange status " + status + ", newStatue " + newState);
super.onConnectionStateChange(gatt, status, newState);
watchDog.cancel();
if ( watchDogAlreadyCalled )
{
return;
}
switch (newState)
{
case BluetoothProfile.STATE_CONNECTED:
mBluetoothGatt = gatt;
onBinded();
NLog.d("Connected");
mtuIndex = 0;
mtu = mtuLIst[mtuIndex];
boolean ret = gatt.requestMtu(mtu);
NLog.d("mtu test result : " + ret);
break;
case BluetoothProfile.STATE_DISCONNECTED:
NLog.d("Disconnected");
if ( mConnectionThread == null )
{
NLog.d("Connect failed");
responseMsg( new PenMsg( PenMsgType.PEN_CONNECTION_FAILURE) );
onDisconnected();
}
else
{
mConnectionThread.stopRunning();
}
close();
break;
}
}