本文整理汇总了Java中android.bluetooth.BluetoothAdapter.STATE_TURNING_OFF属性的典型用法代码示例。如果您正苦于以下问题:Java BluetoothAdapter.STATE_TURNING_OFF属性的具体用法?Java BluetoothAdapter.STATE_TURNING_OFF怎么用?Java BluetoothAdapter.STATE_TURNING_OFF使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.bluetooth.BluetoothAdapter
的用法示例。
在下文中一共展示了BluetoothAdapter.STATE_TURNING_OFF属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: btEnable
@Rpc(description = "Enable bluetooth with a 30s timeout.")
public void btEnable() throws BluetoothAdapterSnippetException, InterruptedException {
if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
return;
}
// If bt is trying to turn off, wait for that to finish before continuing.
if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_TURNING_OFF) {
if (!Utils.waitUntil(
() -> mBluetoothAdapter.getState() == BluetoothAdapter.STATE_OFF,
TIMEOUT_TOGGLE_STATE)) {
Log.e(String.format("BT failed to stabilize after %ss.", TIMEOUT_TOGGLE_STATE));
}
}
if (!mBluetoothAdapter.enable()) {
throw new BluetoothAdapterSnippetException("Failed to start enabling bluetooth");
}
if (!Utils.waitUntil(() -> mBluetoothAdapter.isEnabled(), TIMEOUT_TOGGLE_STATE)) {
throw new BluetoothAdapterSnippetException(
String.format("Bluetooth did not turn on within %ss.", TIMEOUT_TOGGLE_STATE));
}
}
示例2: 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;
}
示例3: 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);
}
示例4: 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;
}
}
}
示例5: 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;
}
}
示例6: 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);
}
示例7: 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";
}
}
示例8: 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;
}
}
示例9: onReceive
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)){
if (isProtected()){
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (device.getAddress().equals(mBTDevice.getAddress())){
request(AntiTheftService.REQUEST_START_ALARM, null);
if (!setSP.isAntiTheftOpenBTEnhancedMode()){
request(AntiTheftService.REQUEST_STOP_PROTECT, null);
request(AntiTheftService.REQUEST_SHOW_MSG, "已绑定蓝牙设备已断开连接,蓝牙防盗服务已自动关闭.");
onProgress(AntiTheftService.MSG_REFESH_VIEWS, null);
}
}
}
}else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)){
int currState = intent.getExtras().getInt(BluetoothAdapter.EXTRA_STATE);
int previusState = intent.getExtras().getInt(BluetoothAdapter.EXTRA_PREVIOUS_STATE);
if ((previusState == BluetoothAdapter.STATE_ON) && (currState == BluetoothAdapter.STATE_TURNING_OFF)){
//蓝牙已被主动关闭
if (setSP.isAntiTheftBTClosedAlarm()){
request(AntiTheftService.REQUEST_START_ALARM, null);
}
request(AntiTheftService.REQUEST_STOP_PROTECT, null);
request(AntiTheftService.REQUEST_SHOW_MSG,"蓝牙已被关闭,蓝牙防盗服务已自动关闭!");
onProgress(AntiTheftService.MSG_REFESH_VIEWS, null);
}
}
}
示例10: 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";
}
}
示例11: 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);
}
示例12: onReceive
@Override
public void onReceive(final Context context, final Intent intent) {
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0);
if (state == BluetoothAdapter.STATE_TURNING_OFF || state == BluetoothAdapter.STATE_OFF) {
log.info("bluetooth was turned off, stopping service");
stopSelf();
}
}
示例13: onReceive
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase(BluetoothAdapter.ACTION_STATE_CHANGED)) {
switch (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) {
case BluetoothAdapter.STATE_ON:
BluetoothSyncService.startOrPromptBluetooth(context);
break;
case BluetoothAdapter.STATE_TURNING_OFF:
case BluetoothAdapter.STATE_OFF:
Intent stopSyncServiceIntent = new Intent(context, BluetoothSyncService.class);
context.stopService(stopSyncServiceIntent);
break;
}
}
}