本文整理汇总了Java中android.bluetooth.BluetoothAdapter.STATE_TURNING_ON属性的典型用法代码示例。如果您正苦于以下问题:Java BluetoothAdapter.STATE_TURNING_ON属性的具体用法?Java BluetoothAdapter.STATE_TURNING_ON怎么用?Java BluetoothAdapter.STATE_TURNING_ON使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.bluetooth.BluetoothAdapter
的用法示例。
在下文中一共展示了BluetoothAdapter.STATE_TURNING_ON属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
}
示例2: 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();
}
}
}
示例3: BluetoothControl20
public BluetoothControl20() {
// cache adaptor
mAdapter = BluetoothAdapter.getDefaultAdapter();
if (mAdapter == null) throw new UnsupportedOperationException("No default bluetooth adapter");
// initialize state
BLUETOOTH_STATE_UNKNOWN = -1;
BLUETOOTH_STATE_OFF = BluetoothAdapter.STATE_OFF;
BLUETOOTH_STATE_TURNING_ON = BluetoothAdapter.STATE_TURNING_ON;
BLUETOOTH_STATE_ON = BluetoothAdapter.STATE_ON;
BLUETOOTH_STATE_TURNING_OFF = BluetoothAdapter.STATE_TURNING_OFF;
BLUETOOTH_ACTION_STATE_CHANGED = BluetoothAdapter.ACTION_STATE_CHANGED;
BLUETOOTH_EXTRA_STATE = BluetoothAdapter.EXTRA_STATE;
}
示例4: handleUpdateState
@Override
public void handleUpdateState(Object state, Object arg) {
mState.visible = true;
mState.booleanValue = false;
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
int btState = adapter == null ? BluetoothAdapter.ERROR : adapter.getState();
if (isInErrorState(btState)) {
mState.label = mGbContext.getString(R.string.qs_tile_bt_tethering_error);
mState.icon = mGbContext.getDrawable(R.drawable.ic_qs_bt_tethering_off);
} else if (btState == BluetoothAdapter.STATE_TURNING_ON ||
btState == BluetoothAdapter.STATE_TURNING_OFF) {
mState.label = "---";
mState.icon = mGbContext.getDrawable(R.drawable.ic_qs_bt_tethering_off);
} else if (btState == BluetoothAdapter.STATE_ON && isTetheringOn()) {
mState.label = mGbContext.getString(R.string.qs_tile_bt_tethering_on);
mState.icon = mGbContext.getDrawable(R.drawable.ic_qs_bt_tethering_on);
mState.booleanValue = true;
} else {
mState.label = mGbContext.getString(R.string.qs_tile_bt_tethering_off);
mState.icon = mGbContext.getDrawable(R.drawable.ic_qs_bt_tethering_off);
}
super.handleUpdateState(state, arg);
}
示例5: onReceive
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
switch (state) {
case BluetoothAdapter.STATE_OFF:
case BluetoothAdapter.STATE_TURNING_OFF:
case BluetoothAdapter.STATE_TURNING_ON:
stopBluetooth();
break;
case BluetoothAdapter.STATE_ON:
startBluetooth();
break;
}
}
}
示例6: 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;
}
}
示例7: isBluetoothOpen
/**
* 判断蓝牙是否打开
*
* @return true:已经打开或者正在打开;false:已经关闭或者正在关闭
* 没有找到蓝牙设备
*/
public static boolean isBluetoothOpen() {
int bluetoothStateCode = 0;
try {
bluetoothStateCode = getBluetoothState();
return bluetoothStateCode == BluetoothAdapter.STATE_ON
|| bluetoothStateCode == BluetoothAdapter.STATE_TURNING_ON ? true
: false;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
示例8: onReceive
@Override
public void onReceive(Context context, Intent intent) {
Log.d(LOG_TAG, "onReceive");
final String action = intent.getAction();
String stringState = "";
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
BluetoothAdapter.ERROR);
switch (state) {
case BluetoothAdapter.STATE_OFF:
stringState = "off";
break;
case BluetoothAdapter.STATE_TURNING_OFF:
stringState = "turning_off";
break;
case BluetoothAdapter.STATE_ON:
stringState = "on";
break;
case BluetoothAdapter.STATE_TURNING_ON:
stringState = "turning_on";
break;
}
}
WritableMap map = Arguments.createMap();
map.putString("state", stringState);
Log.d(LOG_TAG, "state: " + stringState);
sendEvent("BleManagerDidUpdateState", map);
}
示例9: 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";
}
}
示例10: newStateDetected
private void newStateDetected(int state) {
bluetoothState = state;
switch (state) {
case BluetoothAdapter.STATE_OFF:
//Indicates the local Bluetooth adapter is off.
break;
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.
break;
case BluetoothAdapter.STATE_ON:
//Indicates the local Bluetooth adapter is on, and ready for use.
break;
case BluetoothAdapter.STATE_TURNING_OFF:
if (!Pandwarf.getInstance().isConnected()) {
return;
}
killAllProcess(new GollumCallbackGetBoolean() {
@Override
public void done(boolean b) {
EventBus.getDefault().postSticky(new StateEvent(DISCONNECTED, ""));
}
});
//Indicates the local Bluetooth adapter is turning off. Local clients should immediately attempt graceful disconnection of any remote links.
break;
}
}
示例11: 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";
}
}
示例12: onReceive
@Override
public void onReceive(Context context, Intent intent) {
Log.d(LOG_TAG, "onReceive");
final String action = intent.getAction();
String stringState = "";
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
BluetoothAdapter.ERROR);
switch (state) {
case BluetoothAdapter.STATE_OFF:
stringState = "off";
break;
case BluetoothAdapter.STATE_TURNING_OFF:
stringState = "turning_off";
break;
case BluetoothAdapter.STATE_ON:
stringState = "on";
break;
case BluetoothAdapter.STATE_TURNING_ON:
stringState = "turning_on";
break;
}
}
WritableMap map = Arguments.createMap();
map.putString("state", stringState);
Log.d(LOG_TAG, "state: " + stringState);
sendEvent("BleAdminDidUpdateState", map);
}