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


Java BluetoothProfile.STATE_CONNECTING屬性代碼示例

本文整理匯總了Java中android.bluetooth.BluetoothProfile.STATE_CONNECTING屬性的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothProfile.STATE_CONNECTING屬性的具體用法?Java BluetoothProfile.STATE_CONNECTING怎麽用?Java BluetoothProfile.STATE_CONNECTING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.bluetooth.BluetoothProfile的用法示例。


在下文中一共展示了BluetoothProfile.STATE_CONNECTING屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getStateDescription

public static String getStateDescription(int state) {
    switch (state) {
        case BluetoothProfile.STATE_CONNECTED:
            return "Connected";
        case BluetoothProfile.STATE_CONNECTING:
            return "Connecting";
        case BluetoothProfile.STATE_DISCONNECTED:
            return "Disconnected";
        case BluetoothProfile.STATE_DISCONNECTING:
            return "Disconnecting";
        default:
            return "Unknown State "+state;
    }
}
 
開發者ID:holgi-s,項目名稱:RangeThings,代碼行數:14,代碼來源:GattProfile.java

示例2: stateToString

/**
 * Converts the connection state to String value
 * @param state the connection state
 * @return state as String
 */
protected String stateToString(final int state) {
	switch (state) {
		case BluetoothProfile.STATE_CONNECTED:
			return "CONNECTED";
		case BluetoothProfile.STATE_CONNECTING:
			return "CONNECTING";
		case BluetoothProfile.STATE_DISCONNECTING:
			return "DISCONNECTING";
		default:
			return "DISCONNECTED";
	}
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:17,代碼來源:BleManager.java

示例3: isBluetoothHeadsetInUse

/**
 * Check if BT headset is connected
 * @return true if current is playing with BT headset
 */
public boolean isBluetoothHeadsetInUse() {
    BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
    int a2dpState = btAdapter.getProfileConnectionState(BluetoothProfile.HEADSET);
    return (BluetoothProfile.STATE_CONNECTED == a2dpState
            || BluetoothProfile.STATE_CONNECTING == a2dpState);
}
 
開發者ID:KobeMing,項目名稱:FMRadio,代碼行數:10,代碼來源:FmService.java

示例4: getStateDescription

public static String getStateDescription(int state) {
    switch (state) {
        case BluetoothProfile.STATE_CONNECTED:
            return "Connected";
        case BluetoothProfile.STATE_CONNECTING:
            return "Connecting";
        case BluetoothProfile.STATE_DISCONNECTED:
            return "Disconnected";
        case BluetoothProfile.STATE_DISCONNECTING:
            return "Disconnecting";
        default:
            return "Unknown State " + state;
    }
}
 
開發者ID:thejeshgn,項目名稱:BleUARTPeripheral,代碼行數:14,代碼來源:UARTProfile.java

示例5: onConnectionStateChange

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    if (mOnConnectionStateChangeListener != null) {
        mOnConnectionStateChangeListener.onConnectionStateChange(gatt, status, newState);
    }
    String intentAction;
    String tmpAddress = gatt.getDevice().getAddress();
    if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        intentAction = ACTION_GATT_DISCONNECTED;
        Log.i(TAG, "Disconnected from GATT server.");
        broadcastUpdate(intentAction, tmpAddress);
        close(tmpAddress);
    } else if (newState == BluetoothProfile.STATE_CONNECTING) {
        intentAction = ACTION_GATT_CONNECTING;
        Log.i(TAG, "Connecting to GATT server.");
        broadcastUpdate(intentAction, tmpAddress);
    } else if (newState == BluetoothProfile.STATE_CONNECTED) {
        mConnectedAddressList.add(tmpAddress);
        intentAction = ACTION_GATT_CONNECTED;
        broadcastUpdate(intentAction, tmpAddress);
        Log.i(TAG, "Connected to GATT server.");
        // Attempts to discover services after successful connection.
        Log.i(TAG, "Attempting to start service discovery:" +
                mBluetoothGattMap.get(tmpAddress).discoverServices());
    } else if (newState == BluetoothProfile.STATE_DISCONNECTING) {
        mConnectedAddressList.remove(tmpAddress);
        intentAction = ACTION_GATT_DISCONNECTING;
        Log.i(TAG, "Disconnecting from GATT server.");
        broadcastUpdate(intentAction, tmpAddress);
    }
}
 
開發者ID:junkchen,項目名稱:BleLib,代碼行數:31,代碼來源:MultipleBleService.java

示例6: onStatusEvent

private Subscriber<StatusEvent> onStatusEvent() {
    return new Subscriber<StatusEvent>() {
        @Override
        public void onCompleted() {
            Timber.d("completed");
        }

        @Override
        public void onError(Throwable e) {
            Timber.d("error: %s", e.getMessage());
        }

        @Override
        public void onNext(StatusEvent event) {

            device = event.device;
            int deviceState = device.getState();
            Timber.d("device: %s, state: %d", device.getName(), deviceState);

            if (BluetoothProfile.STATE_DISCONNECTED == deviceState) {
                // we are done, notify the UI
                connectivityHeartbeatTimer.cancel();
                if(isConnectivityLost) {
                    isConnectivityLost = false;
                    viewListener.onData(device);
                }
            } else if (BluetoothProfile.STATE_CONNECTED == deviceState && Boolean.TRUE.equals(device.isServicesDiscovered)) {
                // good stuff, we have a status event and the services
                isConnectivityLost = false;
                viewListener.onData(device);
            } else if (BluetoothProfile.STATE_CONNECTING == deviceState) {
                viewListener.onData(device);
            }
        }
    };
}
 
開發者ID:SiliconLabs,項目名稱:thunderboard-android,代碼行數:36,代碼來源:StatusPresenter.java

示例7: connectionState

private String connectionState(int status) {
    switch (status) {
        case BluetoothProfile.STATE_CONNECTED:
            return "Connected";
        case BluetoothProfile.STATE_DISCONNECTED:
            return "Disconnected";
        case BluetoothProfile.STATE_CONNECTING:
            return "Connecting";
        case BluetoothProfile.STATE_DISCONNECTING:
            return "Disconnecting";
        default:
            return String.valueOf(status);
    }
}
 
開發者ID:ruipoliveira,項目名稱:livingCity-Android,代碼行數:14,代碼來源:MainActivity.java

示例8: isBtConnected

/**
 * Check if BT is connected
 * @return true if current is playing with BT earphone
 */
public boolean isBtConnected() {
    BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
    Log.d(TAG, "isBtConnected headset:"
            + btAdapter.getProfileConnectionState(BluetoothProfile.HEADSET)
            + ", a2dp:" + btAdapter.getProfileConnectionState(BluetoothProfile.A2DP));
    int a2dpState = btAdapter.getProfileConnectionState(BluetoothProfile.HEADSET);
    return (BluetoothProfile.STATE_CONNECTED == a2dpState
            || BluetoothProfile.STATE_CONNECTING == a2dpState);
}
 
開發者ID:hyperion70,項目名稱:android_device_MTS_x2605,代碼行數:13,代碼來源:FmRadioService.java

示例9: stateToString

private String stateToString(int state)
{
    if (state == BluetoothProfile.STATE_CONNECTED)
        return "CONNECTED";
    if (state == BluetoothProfile.STATE_CONNECTING)
        return "CONNECTING";
    if (state == BluetoothProfile.STATE_DISCONNECTED)
        return "DISCONNECTED";
    if (state == BluetoothProfile.STATE_DISCONNECTING)
        return "DISCONNECTING";

    return String.format("Unknown state %d (0x%08X)", state, state);
}
 
開發者ID:NordicID,項目名稱:nur_sample_android,代碼行數:13,代碼來源:UartService.java

示例10: onConnectionStateChange

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    if (mOnConnectionStateChangeListener != null) {
        mOnConnectionStateChangeListener.onConnectionStateChange(gatt, status, newState);
    }
    String intentAction;
    String address = gatt.getDevice().getAddress();
    if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        Log.i(TAG, "onConnectionStateChange: DISCONNECTED: " + getConnectDevices().size());
        intentAction = ACTION_GATT_DISCONNECTED;
        isConnect = false;
        mConnState = STATE_DISCONNECTED;
        Log.i(TAG, "Disconnected from GATT server.");
        broadcastUpdate(intentAction, address);
        close();
    } else if (newState == BluetoothProfile.STATE_CONNECTING) {
        Log.i(TAG, "onConnectionStateChange: CONNECTING: " + getConnectDevices().size());
        isConnect = false;
        intentAction = ACTION_GATT_CONNECTING;
        mConnState = STATE_CONNECTING;
        Log.i(TAG, "Connecting to GATT server.");
        broadcastUpdate(intentAction, address);
    } else if (newState == BluetoothProfile.STATE_CONNECTED) {
        Log.i(TAG, "onConnectionStateChange: CONNECTED: " + getConnectDevices().size());
        intentAction = ACTION_GATT_CONNECTED;
        isConnect = true;
        mConnState = STATE_CONNECTED;
        broadcastUpdate(intentAction, address);
        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_DISCONNECTING) {
        Log.i(TAG, "onConnectionStateChange: DISCONNECTING: " + getConnectDevices().size());
        isConnect = false;
        intentAction = ACTION_GATT_DISCONNECTING;
        mConnState = STATE_DISCONNECTING;
        Log.i(TAG, "Disconnecting from GATT server.");
        broadcastUpdate(intentAction, address);
    }
}
 
開發者ID:junkchen,項目名稱:BleLib,代碼行數:41,代碼來源:BleService.java

示例11: onConnectionStateChange

/**
 * Defined what to do when the status of the Bluetooth change
 *
 * @param gatt The BluetoothGatt
 * @param status The previous state of the Bluetooth
 * @param newState The new state of the Bluetooth
 */
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {

    StretchSensePeripheralConnected peripheralChanging = getDeviceFromGatt(gatt);

    if (newState == BluetoothProfile.STATE_CONNECTED) {
        peripheralChanging.state = STATE_CONNECTED;

        if (mBleListener != null) {
            mBleListener.onConnected();
        }
        // Attempts to discover services after successful connection.
        gatt.discoverServices();

    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        peripheralChanging.state = STATE_DISCONNECTED;
        String addressOfTheDeviceChangingStatus = peripheralChanging.id;
        int indexToRemove = -1;
        for (StretchSensePeripheralConnected myPeripheralConnected: listStretchSensePeripheralsConnected) {

            if (myPeripheralConnected.id.equals(addressOfTheDeviceChangingStatus)){
                indexToRemove = listStretchSensePeripheralsConnected.indexOf(myPeripheralConnected);
            }
        }
        if (indexToRemove != -1) {
            listStretchSensePeripheralsConnected.remove(indexToRemove);
        }

        indexToRemove = -1;
        for (StretchSensePeripheralAvailable myPeripheralAvailable: listStretchSensePeripheralsAvailable) {

            if (myPeripheralAvailable.id.equals(addressOfTheDeviceChangingStatus)){
                indexToRemove = listStretchSensePeripheralsAvailable.indexOf(myPeripheralAvailable);
            }
        }

        if (indexToRemove != -1) {
            listStretchSensePeripheralsAvailable.remove(indexToRemove);
        }


        if (mBleListener != null) {
            mBleListener.onDisconnected();
        }

    } else if (newState == BluetoothProfile.STATE_CONNECTING) {
        peripheralChanging.state = STATE_CONNECTING;
        if (mBleListener != null) {
            mBleListener.onConnecting();
        }
    }
}
 
開發者ID:StretchSense,項目名稱:Android-Library,代碼行數:59,代碼來源:StretchSenseLibraryManager.java

示例12: onConnectionStateChange

/**
 * Defined what to do when the status of the Bluetooth change
 *
 * @param gatt The BluetoothGatt
 * @param status The previous state of the Bluetooth
 * @param newState The new state of the Bluetooth
 */
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {

    StretchSensePeripheralConnected peripheralChanging = getDeviceFromGatt(gatt);
    //Log.i("BleManager()", "onConnectionStateChange() my " + deviceChanging.toString());

    if (newState == BluetoothProfile.STATE_CONNECTED) {
        //mConnectionState = STATE_CONNECTED;
        peripheralChanging.state = STATE_CONNECTED;

        if (mBleListener != null) {
            mBleListener.onConnected();
        }
        // Attempts to discover services after successful connection.
        gatt.discoverServices();

    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        //mConnectionState = STATE_DISCONNECTED;
        peripheralChanging.state = STATE_DISCONNECTED;
        String addressOfTheDeviceChangingStatus = peripheralChanging.id;
        int indexToRemove = -1;
        for (StretchSensePeripheralConnected myPeripheralConnected: listStretchSensePeripheralsConnected) {

            if (myPeripheralConnected.id.equals(addressOfTheDeviceChangingStatus)){
                indexToRemove = listStretchSensePeripheralsConnected.indexOf(myPeripheralConnected);
            }
        }
        if (indexToRemove != -1) {
            listStretchSensePeripheralsConnected.remove(indexToRemove);
        }

        indexToRemove = -1;
        for (StretchSensePeripheralAvailable myPeripheralAvailable: listStretchSensePeripheralsAvailable) {

            if (myPeripheralAvailable.id.equals(addressOfTheDeviceChangingStatus)){
                indexToRemove = listStretchSensePeripheralsAvailable.indexOf(myPeripheralAvailable);
            }
        }

        if (indexToRemove != -1) {
            listStretchSensePeripheralsAvailable.remove(indexToRemove);
        }


        if (mBleListener != null) {
            mBleListener.onDisconnected();
        }

    } else if (newState == BluetoothProfile.STATE_CONNECTING) {
        peripheralChanging.state = STATE_CONNECTING;
        if (mBleListener != null) {
            mBleListener.onConnecting();
        }
    }
}
 
開發者ID:StretchSense,項目名稱:Android-Library,代碼行數:62,代碼來源:StretchSenseLibraryManager.java

示例13: onConnectionStateChange

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    LOG.debug("connection state change, newState: " + newState + getStatusString(status));

    synchronized (mGattMonitor) {
        if (mBluetoothGatt == null) {
            mBluetoothGatt = gatt;
        }
    }

    if (!checkCorrectGattInstance(gatt, "connection state event")) {
        return;
    }

    if (status != BluetoothGatt.GATT_SUCCESS) {
        LOG.warn("connection state event with error status " + status);
    }

    switch (newState) {
        case BluetoothProfile.STATE_CONNECTED:
            LOG.info("Connected to GATT server.");
            setDeviceConnectionState(State.CONNECTED);
            // Attempts to discover services after successful connection.
            List<BluetoothGattService> cachedServices = gatt.getServices();
            if (cachedServices != null && cachedServices.size() > 0) {
                LOG.info("Using cached services, skipping discovery");
                onServicesDiscovered(gatt, BluetoothGatt.GATT_SUCCESS);
            } else {
                LOG.info("Attempting to start service discovery:" +
                        gatt.discoverServices());
            }
            break;
        case BluetoothProfile.STATE_DISCONNECTED:
            LOG.info("Disconnected from GATT server.");
            handleDisconnected(status);
            break;
        case BluetoothProfile.STATE_CONNECTING:
            LOG.info("Connecting to GATT server...");
            setDeviceConnectionState(State.CONNECTING);
            break;
    }
}
 
開發者ID:scifiswapnil,項目名稱:gadgetbridge_artikcloud,代碼行數:42,代碼來源:BtLEQueue.java


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