当前位置: 首页>>代码示例>>Java>>正文


Java BluetoothProfile.STATE_DISCONNECTED属性代码示例

本文整理汇总了Java中android.bluetooth.BluetoothProfile.STATE_DISCONNECTED属性的典型用法代码示例。如果您正苦于以下问题:Java BluetoothProfile.STATE_DISCONNECTED属性的具体用法?Java BluetoothProfile.STATE_DISCONNECTED怎么用?Java BluetoothProfile.STATE_DISCONNECTED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.bluetooth.BluetoothProfile的用法示例。


在下文中一共展示了BluetoothProfile.STATE_DISCONNECTED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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.");
    }
}
 
开发者ID:skydoves,项目名称:MagicLight-Controller,代码行数:23,代码来源:BluetoothLeService.java

示例2: connect

/**
     * Connects to the GATT server hosted on the Bluetooth LE device.
     *
     * @param address The device address of the destination device.
     * @return Return true if the connection is initiated successfully. The connection result is reported asynchronously through the
     * {@code BluetoothGattCallback#onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)} callback.
     */
    public void connect(final String address, IBleDeviceListener iBleDeviceListener) {
        UdooBluException udooBluException = checkBluetooth(getApplicationContext());
        if (udooBluException != null) {
            if (iBleDeviceListener != null)
                iBleDeviceListener.onError(udooBluException);
        } else {
            final BluetoothDevice device = mBtAdapter.getRemoteDevice(address);
            int connectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT);

            BluetoothGatt bluetoothGatt = checkAndGetGattItem(address);
            if (connectionState == BluetoothProfile.STATE_DISCONNECTED) {
//                 Previously connected device. Try to reconnect.
                if (bluetoothGatt != null) {
                    Log.d(TAG, "Re-use GATT connection");
                    if (bluetoothGatt.connect()) {
                    } else {
                        Log.w(TAG, "GATT re-connect failed.");
                    }
                } else if (device == null) {
                    Log.w(TAG, "Device not found.  Unable to connect.");
                } else {
                    Log.d(TAG, "Create a new GATT connection.");
                    bluetoothGatt = device.connectGatt(this, false, bluetoothGattCallbackBuilder());
                    mBluetoothGatts.put(address, bluetoothGatt);
                }
            } else {
                Log.w(TAG, "Attempt to connect in state: " + connectionState);
                bond(address);
                bluetoothGatt = device.connectGatt(this, false, bluetoothGattCallbackBuilder());
                mBluetoothGatts.put(address, bluetoothGatt);
            }
        }
    }
 
开发者ID:UDOOboard,项目名称:UDOOBluLib-android,代码行数:40,代码来源:UdooBluService.java

示例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();
    }
}
 
开发者ID:e-regular-games,项目名称:arduator,代码行数:18,代码来源:ArduinoCommBle.java

示例4: 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);
    }
}
 
开发者ID:richhowley,项目名称:Android-BLE-to-Arduino,代码行数:19,代码来源:BluetoothLeService.java

示例5: 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");

}
 
开发者ID:haoyifan,项目名称:BLE-PEPS,代码行数:21,代码来源:BluetoothLeClass.java

示例6: onReceive

public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(A2dpSinkHelper.ACTION_CONNECTION_STATE_CHANGED)) {
        int oldState = A2dpSinkHelper.getPreviousProfileState(intent);
        int newState = A2dpSinkHelper.getCurrentProfileState(intent);
        BluetoothDevice device = A2dpSinkHelper.getDevice(intent);
        Log.d(TAG, "Bluetooth A2DP sink changing connection state from " + oldState +
                " to " + newState + " device " + device);
        if (device != null) {
            String deviceName = Objects.toString(device.getName(), "a device");
            if (newState == BluetoothProfile.STATE_CONNECTED) {
                speak("Connected to " + deviceName);
            } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                speak("Disconnected from " + deviceName);
            }
        }
    }
}
 
开发者ID:androidthings,项目名称:sample-bluetooth-audio,代码行数:17,代码来源:A2dpSinkActivity.java

示例7: onConnectionStateChange

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status,
                                    int newState) {
    if (newState == BluetoothProfile.STATE_CONNECTED) {
        resetConnectionTimeoutChecker();

        isSnachConnected = true;

        BLEManager.this.gatt = gatt; // TODO check if right device is discovered (instead of another BLE device with a different GATT..)
        Log.i("BLE", "Connected to GATT server.");
        Log.i("BLE", "Attempting to start service discovery:" + startServiceDiscovery(gatt));

        sendBroadcastConnectionChanged(isSnachConnected);

    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        isSnachConnected = false;
        mConnectionListener.ConnectionLost();
        Log.i("BLE", "Disconnected from GATT server.");
    }
}
 
开发者ID:ordsen,项目名称:Snach-Android,代码行数:20,代码来源:BLEManager.java

示例8: disconnect

/**
 * Disconnects an existing connection or cancel a pending connection. The disconnection result is reported asynchronously through the
 * {@code BluetoothGattCallback#onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)} callback.
 */
public void disconnect(String address) {
    if (mBtAdapter == null) {
        Log.w(TAG, "disconnect: BluetoothAdapter not initialized");
        return;
    }
    final BluetoothDevice device = mBtAdapter.getRemoteDevice(address);
    int connectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT);
    BluetoothGatt bluetoothGatt = checkAndGetGattItem(address);
    if (bluetoothGatt != null) {
        Log.i(TAG, "disconnect");
        if (connectionState != BluetoothProfile.STATE_DISCONNECTED) {
            bluetoothGatt.disconnect();
        } else {
            Log.w(TAG, "Attempt to disconnect in state: " + connectionState);
        }
    }
}
 
开发者ID:UDOOboard,项目名称:UDOOBluLib-android,代码行数:21,代码来源:UdooBluService.java

示例9: 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;
	}
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:22,代码来源:BluetoothClientService.java

示例10: 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.");

    }
}
 
开发者ID:hcmlab,项目名称:ssj,代码行数:19,代码来源:BLESensorListener.java

示例11: 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());
    }
}
 
开发者ID:Grasea,项目名称:Grandroid2,代码行数:21,代码来源:BluetoothLeService.java

示例12: 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);
    }
}
 
开发者ID:nladuo,项目名称:IoT-Firstep,代码行数:17,代码来源:BluetoothLeService.java

示例13: 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();
    }
}
 
开发者ID:ruipoliveira,项目名称:livingCity-Android,代码行数:23,代码来源:MainActivity.java

示例14: 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, gatt.getDevice());
		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.");
		gatt.close();
		broadcastUpdate(intentAction, gatt.getDevice());
	}
}
 
开发者ID:tharvey,项目名称:BlocklyBot,代码行数:20,代码来源:BluetoothLeService.java

示例15: 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();
            }
		}
	}
}
     }
 
开发者ID:blxble,项目名称:mesh-core-on-android,代码行数:34,代码来源:JniCallbacks.java


注:本文中的android.bluetooth.BluetoothProfile.STATE_DISCONNECTED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。