本文整理汇总了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);
}
示例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
}
}
示例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));
}
}
示例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;
}
}
示例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();
}
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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();
}
}
}
示例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();
}
示例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;
}
}
}
示例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";
}
}
示例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;
}
}
}
示例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();
}
}
示例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";
}
}