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


Java BluetoothAdapter.STATE_OFF属性代码示例

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


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

示例1: checkState

@ReactMethod
public void checkState(){
	Log.d(LOG_TAG, "checkState");

	BluetoothAdapter adapter = getBluetoothAdapter();
	String state = "off";
	if (adapter != null) {
		switch (adapter.getState()) {
			case BluetoothAdapter.STATE_ON:
				state = "on";
				break;
			case BluetoothAdapter.STATE_OFF:
				state = "off";
		}
	}

	WritableMap map = Arguments.createMap();
	map.putString("state", state);
	Log.d(LOG_TAG, "state:" + state);
	sendEvent("BleManagerDidUpdateState", map);
}
 
开发者ID:lenglengiOS,项目名称:react-native-blue-manager,代码行数:21,代码来源:BleManager.java

示例2: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);

    switch (state) {
        case BluetoothAdapter.STATE_ON:
            startAdvertising();
            startServer();
            break;
        case BluetoothAdapter.STATE_OFF:
            stopServer();
            stopAdvertising();
            break;
        default:
            // Do nothing
    }

}
 
开发者ID:androidthings,项目名称:sample-bluetooth-le-gattserver,代码行数:18,代码来源:GattServerActivity.java

示例3: btDisable

@Rpc(description = "Disable bluetooth with a 30s timeout.")
public void btDisable() throws BluetoothAdapterSnippetException, InterruptedException {
    if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_OFF) {
        return;
    }
    // If bt is trying to turn on, wait for that to finish before continuing.
    if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_TURNING_ON) {
        if (!Utils.waitUntil(
                () -> mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON,
                TIMEOUT_TOGGLE_STATE)) {
            Log.e(String.format("BT failed to stabilize after %ss.", TIMEOUT_TOGGLE_STATE));
        }
    }
    if (!mBluetoothAdapter.disable()) {
        throw new BluetoothAdapterSnippetException("Failed to start disabling bluetooth");
    }
    if (!Utils.waitUntil(() -> !mBluetoothAdapter.isEnabled(), TIMEOUT_TOGGLE_STATE)) {
        throw new BluetoothAdapterSnippetException(
                String.format("Bluetooth did not turn off within %ss.", TIMEOUT_TOGGLE_STATE));
    }
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:21,代码来源:BluetoothAdapterSnippet.java

示例4: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
        case BluetoothAdapter.ACTION_STATE_CHANGED:
            int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
            switch (state) {
                case BluetoothAdapter.STATE_TURNING_ON:// 蓝牙打开中

                    break;
                case BluetoothAdapter.STATE_ON:// 蓝牙打开完成

                    break;
                case BluetoothAdapter.STATE_TURNING_OFF:// 蓝牙关闭中

                    break;
                case BluetoothAdapter.STATE_OFF:// 蓝牙关闭完成

                    break;
                default:
                    break;
            }
        default:
            break;
    }
}
 
开发者ID:RockyQu,项目名称:BluetoothKit,代码行数:25,代码来源:BluetoothReceiver.java

示例5: onReceive

public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
        int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
        switch (state) {
            case BluetoothAdapter.STATE_OFF:
                snackTurnOn.show();
                break;
            case BluetoothAdapter.STATE_TURNING_ON:
                if (snackTurnOn.isShownOrQueued()) snackTurnOn.dismiss();
                break;
            case BluetoothAdapter.STATE_ON:
                reconnect();
        }
    }
}
 
开发者ID:bilal-rashid,项目名称:Lazy-Switches,代码行数:17,代码来源:BluetoothActivity.java

示例6: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);

    switch (state) {
        case BluetoothAdapter.STATE_ON:
            startAdvertising();
            startServer();
            break;
        case BluetoothAdapter.STATE_OFF:
            stopServer();
            stopAdvertising();
            break;
        default:
            // Do nothing
            break;
    }
}
 
开发者ID:Nilhcem,项目名称:blefun-androidthings,代码行数:18,代码来源:GattServer.java

示例7: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);

    switch (state) {
        case BluetoothAdapter.STATE_ON:
            startClient();
            break;
        case BluetoothAdapter.STATE_OFF:
            stopClient();
            break;
        default:
            // Do nothing
            break;
    }
}
 
开发者ID:Nilhcem,项目名称:blefun-androidthings,代码行数:16,代码来源:GattClient.java

示例8: checkState

public void checkState(){
	Log.d(LOG_TAG, "checkState");

	BluetoothAdapter adapter = getBluetoothAdapter();
	String state = "off";
	switch (adapter.getState()){
		case BluetoothAdapter.STATE_ON:
			state = "on";
			break;
		case BluetoothAdapter.STATE_OFF:
			state = "off";
	}

	WritableMap map = Arguments.createMap();
	map.putString("state", state);
	Log.d(LOG_TAG, "state:" + state);
	sendEvent("BleAdminDidUpdateState", map);
}
 
开发者ID:YbrainInc,项目名称:react-native-ble-quick-sdk,代码行数:18,代码来源:BleAdmin.java

示例9: initBluetooth

/**
 * enable bluetooth
 */
private void initBluetooth() {
    //get Bluetooth service
    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    //get Bluetooth Adapter
    mBluetoothAdapter = mBluetoothManager.getAdapter();
    if (mBluetoothAdapter == null) {//platform not support bluetooth
        Log.d(Tag, "Bluetooth is not support");
    }
    else{
        int status = mBluetoothAdapter.getState();
        //bluetooth is disabled
        if (status == BluetoothAdapter.STATE_OFF) {
            // enable bluetooth
            mBluetoothAdapter.enable();
        }
    }
}
 
开发者ID:wuhighway,项目名称:DailyStudy,代码行数:20,代码来源:BleActivity.java

示例10: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
        int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
                BluetoothAdapter.ERROR);
        if (DEBUG) log("Bluetooth state changed: state=" + state +
                "; mBluetoothEnableForTether=" + mBluetoothEnableForTether);
        switch (state) {
            case BluetoothAdapter.STATE_ON:
                registerServiceListener();
                break;
            case BluetoothAdapter.STATE_OFF:
            case BluetoothAdapter.ERROR:
                unregisterServiceListener();
                break;
            default:
                // ignore transition states
        }
    }
    refreshState();
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:21,代码来源:BluetoothTetheringTile.java

示例11: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    Logger.getInstance().Debug(TAG, "_bluetoothChangedReceiver");

    final String action = intent.getAction();
    if (action == null) {
        Logger.getInstance().Error(TAG, "_bluetoothChangedReceiver action is null");
        return;
    }
    Logger.getInstance().Debug(TAG, String.format(Locale.getDefault(), "Action is %s", action));

    if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
        final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
        Logger.getInstance().Debug(TAG, String.format(Locale.getDefault(), "State is %d", state));

        switch (state) {
            case BluetoothAdapter.STATE_OFF:
                _bluetoothIsEnabled = false;
                if (_beaconManager.isBound(PositioningService.this)) {
                    _beaconManager.unbind(PositioningService.this);
                }
                break;

            case BluetoothAdapter.STATE_ON:
                _bluetoothIsEnabled = true;
                SetScanEnabled(_scanEnabled);
                break;

            default:
                break;
        }
    }

}
 
开发者ID:GuepardoApps,项目名称:LucaHome-AndroidApplication,代码行数:34,代码来源:PositioningService.java

示例12: stateToString

/**
 * Converts BluetoothAdapter states into local string representations.
 */
private String stateToString(int state) {
    switch (state) {
        case BluetoothAdapter.STATE_DISCONNECTED:
            return "DISCONNECTED";
        case BluetoothAdapter.STATE_CONNECTED:
            return "CONNECTED";
        case BluetoothAdapter.STATE_CONNECTING:
            return "CONNECTING";
        case BluetoothAdapter.STATE_DISCONNECTING:
            return "DISCONNECTING";
        case BluetoothAdapter.STATE_OFF:
            return "OFF";
        case BluetoothAdapter.STATE_ON:
            return "ON";
        case BluetoothAdapter.STATE_TURNING_OFF:
            // Indicates the local Bluetooth adapter is turning off. Local clients should immediately
            // attempt graceful disconnection of any remote links.
            return "TURNING_OFF";
        case BluetoothAdapter.STATE_TURNING_ON:
            // Indicates the local Bluetooth adapter is turning on. However local clients should wait
            // for STATE_ON before attempting to use the adapter.
            return "TURNING_ON";
        default:
            return "INVALID";
    }
}
 
开发者ID:nhancv,项目名称:nc-android-webrtcpeer,代码行数:29,代码来源:BluetoothManager.java

示例13: onBluetoothStatusChanged

/**
 * Called when the Bluetooth status changed.
 */
public void onBluetoothStatusChanged() {
    // Does anything only if a device discovery has been scheduled.
    if (bluetoothDiscoveryScheduled) {

        int bluetoothState = bluetooth.getState();
        switch (bluetoothState) {
            case BluetoothAdapter.STATE_ON:
                // Bluetooth is ON.
                Log.d(TAG, "Bluetooth succesfully enabled, starting discovery");
                startDiscovery();
                // Resets the flag since this discovery has been performed.
                bluetoothDiscoveryScheduled = false;
                break;
            case BluetoothAdapter.STATE_OFF:
                // Bluetooth is OFF.
                Log.d(TAG, "Error while turning Bluetooth on.");
                Toast.makeText(context, "Error while turning Bluetooth on.", Toast.LENGTH_SHORT);
                // Resets the flag since this discovery has been performed.
                bluetoothDiscoveryScheduled = false;
                break;
            default:
                // Bluetooth is turning ON or OFF. Ignore.
                break;
        }
    }
}
 
开发者ID:aurasphere,项目名称:blue-pair,代码行数:29,代码来源:BluetoothController.java

示例14: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)
            && intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)
                == BluetoothAdapter.STATE_OFF) {
        //Device has disconnected
        Toast.makeText(BluetoothConnector.this, R.string.bluetooth_required_leaving,
                Toast.LENGTH_LONG).show();
        BluetoothConnector.this.finish();
    }
}
 
开发者ID:FelixWohlfrom,项目名称:Presenter-Client-Android,代码行数:13,代码来源:BluetoothConnector.java

示例15: stateToString

/** Converts BluetoothAdapter states into local string representations. */
private String stateToString(int state) {
  switch (state) {
    case BluetoothAdapter.STATE_DISCONNECTED:
      return "DISCONNECTED";
    case BluetoothAdapter.STATE_CONNECTED:
      return "CONNECTED";
    case BluetoothAdapter.STATE_CONNECTING:
      return "CONNECTING";
    case BluetoothAdapter.STATE_DISCONNECTING:
      return "DISCONNECTING";
    case BluetoothAdapter.STATE_OFF:
      return "OFF";
    case BluetoothAdapter.STATE_ON:
      return "ON";
    case BluetoothAdapter.STATE_TURNING_OFF:
      // Indicates the local Bluetooth adapter is turning off. Local clients should immediately
      // attempt graceful disconnection of any remote links.
      return "TURNING_OFF";
    case BluetoothAdapter.STATE_TURNING_ON:
      // Indicates the local Bluetooth adapter is turning on. However local clients should wait
      // for STATE_ON before attempting to use the adapter.
      return  "TURNING_ON";
    default:
      return "INVALID";
  }
}
 
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:27,代码来源:AppRTCBluetoothManager.java


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