當前位置: 首頁>>代碼示例>>Java>>正文


Java BluetoothManager.getConnectedDevices方法代碼示例

本文整理匯總了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();
}
 
開發者ID:LadyViktoria,項目名稱:wearDrip,代碼行數:41,代碼來源:DexCollectionService.java

示例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();
}
 
開發者ID:renyuneyun,項目名稱:Easer,代碼行數:15,代碼來源:BTDeviceSlot.java

示例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());
}
 
開發者ID:NightscoutFoundation,項目名稱:xDrip,代碼行數:43,代碼來源:ListenerService.java

示例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;
    }
}
 
開發者ID:NightscoutFoundation,項目名稱:xDrip,代碼行數:51,代碼來源:DexShareCollectionService.java

示例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();
}
 
開發者ID:NightscoutFoundation,項目名稱:xDrip,代碼行數:64,代碼來源:DexCollectionService.java


注:本文中的android.bluetooth.BluetoothManager.getConnectedDevices方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。