本文整理匯總了Java中android.bluetooth.BluetoothManager.getConnectedDevices方法的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothManager.getConnectedDevices方法的具體用法?Java BluetoothManager.getConnectedDevices怎麽用?Java BluetoothManager.getConnectedDevices使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.bluetooth.BluetoothManager
的用法示例。
在下文中一共展示了BluetoothManager.getConnectedDevices方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: attemptConnection
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
public void attemptConnection() {
final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
if (bluetoothManager == null) {
setRetryTimer();
return;
}
mBluetoothAdapter = bluetoothManager.getAdapter();
if (mBluetoothAdapter == null) {
setRetryTimer();
return;
}
if (device != null) {
mConnectionState = STATE_DISCONNECTED;
for (BluetoothDevice bluetoothDevice : bluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
if (bluetoothDevice.getAddress().compareTo(device.getAddress()) == 0) {
mConnectionState = STATE_CONNECTED;
}
}
}
Log.i(TAG, "attemptConnection: Connection state: " + getStateStr(mConnectionState));
if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) {
ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
if (btDevice != null) {
String deviceAddress = btDevice.address;
if (mBluetoothAdapter.isEnabled() && mBluetoothAdapter.getRemoteDevice(deviceAddress) != null) {
connect(deviceAddress);
return;
}
}
} else if (mConnectionState == STATE_CONNECTED) { //WOOO, we are good to go, nothing to do here!
Log.i(TAG, "attemptConnection: Looks like we are already connected, going to read!");
return;
}
setRetryTimer();
}
示例2: check
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
@Override
public void check() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
for (int profile : new int[]{BluetoothProfile.GATT, BluetoothProfile.GATT_SERVER}) {
for (BluetoothDevice btDevice : bluetoothManager.getConnectedDevices(profile)) {
if (is_target(btDevice)) {
matched_devices++;
}
}
}
}
determine_satisfied();
}
示例3: sendCollectorStatus
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
private void sendCollectorStatus (Context context, String path) {
String msg;
//long last_timestamp = 0;
DataMap dataMap = new DataMap();
switch (DexCollectionType.getDexCollectionType()) {
case DexcomG5:
if (DexCollectionType.getCollectorServiceClass() == G5CollectionService.class) {
dataMap = G5CollectionService.getWatchStatus();//msg, last_timestamp
} else {
dataMap = Ob1G5CollectionService.getWatchStatus();//msg, last_timestamp
}
break;
case DexcomShare://TODO getLastState() in non-G5 Services
BluetoothManager mBluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
ActiveBluetoothDevice activeBluetoothDevice = ActiveBluetoothDevice.first();
boolean connected = false;
if (mBluetoothManager != null && activeBluetoothDevice != null) {
for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
if (bluetoothDevice.getAddress().compareTo(activeBluetoothDevice.address) == 0) {
connected = true;
}
}
}
if (connected) {
msg = "Connected on watch";
} else {
msg = "Not Connected";
}
dataMap.putString("lastState", msg);
break;
default:
dataMap = DexCollectionService.getWatchStatus();
break;
}
if (dataMap != null) {
dataMap.putString("action_path", path);
}
//sendReplyMsg (msg, last_timestamp, path, false);
sendData(WEARABLE_REPLYMSG_PATH, dataMap.toByteArray());
}
示例4: attemptConnection
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
public void attemptConnection() {
mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
if (mBluetoothManager != null) {
if (device != null) {
mConnectionState = STATE_DISCONNECTED;
for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
if (bluetoothDevice.getAddress().compareTo(device.getAddress()) == 0) {
mConnectionState = STATE_CONNECTED;
}
}
}
Log.i(TAG, "Connection state: " + mConnectionState);
if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) {
ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
if (btDevice != null) {
mDeviceName = btDevice.name;
mDeviceAddress = btDevice.address;
mBluetoothAdapter = mBluetoothManager.getAdapter();
try {
if (mBluetoothAdapter.isEnabled() && mBluetoothAdapter.getRemoteDevice(mDeviceAddress) != null) {
connect(mDeviceAddress);
return;
} else {
Log.w(TAG, "Bluetooth is disabled or BT device cant be found");
setRetryTimer();
return;
}
} catch (IllegalArgumentException e) {
if (JoH.ratelimit("dex-share-error-log", 180)) {
Log.wtf(TAG, "Error connecting: " + e);
}
}
} else {
Log.w(TAG, "No bluetooth device to try and connect to");
setRetryTimer();
return;
}
} else if (mConnectionState == STATE_CONNECTED) {
Log.i(TAG, "Looks like we are already connected, going to read!");
attemptRead();
return;
} else {
setRetryTimer();
return;
}
} else {
setRetryTimer();
return;
}
}
示例5: checkConnection
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
synchronized void checkConnection() {
status("Attempting connection");
final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
if (bluetoothManager == null) {
status("No bluetooth manager");
setRetryTimer();
return;
}
mBluetoothAdapter = bluetoothManager.getAdapter();
if (mBluetoothAdapter == null) {
status("No bluetooth adapter");
setRetryTimer();
return;
}
if (!mBluetoothAdapter.isEnabled()) {
if (Pref.getBoolean("automatically_turn_bluetooth_on",true)) {
Log.i(TAG, "Turning bluetooth on as appears disabled");
status("Turning bluetooth on");
JoH.setBluetoothEnabled(getApplicationContext(), true);
} else {
Log.d(TAG,"Not automatically turning on bluetooth due to preferences");
}
}
if (device != null) {
mConnectionState = STATE_DISCONNECTED;
for (BluetoothDevice bluetoothDevice : bluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
if (bluetoothDevice.getAddress().compareTo(device.getAddress()) == 0) {
mConnectionState = STATE_CONNECTED;
}
}
}
Log.i(TAG, "checkConnection: Connection state: " + getStateStr(mConnectionState));
if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) {
final ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
if (btDevice != null) {
final String deviceAddress = btDevice.address;
mDeviceAddress = deviceAddress;
try {
if (mBluetoothAdapter.isEnabled() && mBluetoothAdapter.getRemoteDevice(deviceAddress) != null) {
status("Connecting" + (Home.get_engineering_mode() ? ": "+deviceAddress : ""));
connect(deviceAddress);
mStaticState = mConnectionState;
return;
}
} catch (IllegalArgumentException e) {
Log.e(TAG, "IllegalArgumentException: " + e);
}
}
} else if (mConnectionState == STATE_CONNECTED) { //WOOO, we are good to go, nothing to do here!
status("Last Connected");
Log.i(TAG, "checkConnection: Looks like we are already connected, ready to receive");
mStaticState = mConnectionState;
if (use_polling && (JoH.msSince(lastPacketTime) >= POLLING_PERIOD)) {
pollForData();
}
return;
}
setRetryTimer();
}