Java Code Examples for android.bluetooth.BluetoothAdapter#ERROR
The following examples show how to use
android.bluetooth.BluetoothAdapter#ERROR .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BluetoothStateReceiver.java From EFRConnect-android with Apache License 2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action == null) { return; } if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); switch (state) { case BluetoothAdapter.ERROR: case BluetoothAdapter.STATE_OFF: case BluetoothAdapter.STATE_TURNING_OFF: notifyState(false); break; case BluetoothAdapter.STATE_ON: notifyState(true); break; } } }
Example 2
Source File: BluetoothTetheringTile.java From GravityBox with Apache License 2.0 | 6 votes |
@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(); }
Example 3
Source File: BluetoothTetheringTile.java From GravityBox with Apache License 2.0 | 6 votes |
@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); }
Example 4
Source File: BluetoothBroadcastReceiver.java From bluetooth-a2dp with Apache License 2.0 | 6 votes |
@Override public void onReceive (Context context, Intent intent) { if (!BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) { Log.v(TAG, "Received irrelevant broadcast. Disregarding."); return; } //This is a State Change event, get the state extra, falling back to ERROR //if it isn't there (which shouldn't happen) int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); switch (state) { case BluetoothAdapter.STATE_CONNECTED: safeUnregisterReceiver(context, this); fireOnBluetoothConnected(); break; case BluetoothAdapter.ERROR: safeUnregisterReceiver(context, this); fireOnBluetoothError(); break; } }
Example 5
Source File: BluetoothTetheringTile.java From GravityBox with Apache License 2.0 | 5 votes |
private boolean isInErrorState(int btState) { if (btState == BluetoothAdapter.ERROR) return true; for (String s : getTetheringErroredIfaces()) { for (String regex : getTetherableBluetoothRegexs()) { if (s.matches(regex)) return true; } } return false; }
Example 6
Source File: P_BleManager_Listeners.java From AsteroidOSSync with GNU General Public License v3.0 | 4 votes |
final void onNativeBleStateChangeFromBroadcastReceiver(Context context, Intent intent) { final int previousNativeState = intent.getExtras().getInt(BluetoothAdapter.EXTRA_PREVIOUS_STATE); final int newNativeState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); int logLevel = newNativeState == BluetoothAdapter.ERROR || previousNativeState == BluetoothAdapter.ERROR ? Log.WARN : Log.INFO; m_mngr.getLogger().log(logLevel, "previous=" + m_mngr.getLogger().gattBleState(previousNativeState) + " new=" + m_mngr.getLogger().gattBleState(newNativeState)); if (Utils.isMarshmallow()) { //--- > RB Commenting all this logic out. It's my opinion that we should never ignore native callbacks. Granted, we also poll the native //--- state on devices running Marshmallow or higher, but there are times when polling is insufficient (we could potentially get several //--- broadcasts between update ticks). So we'll just check if we're already checking the state, if not, we filter this broadcast through //--- to the system. // If in the IDLE state, we will pass the state change through as if pre 6.0, and bump out of the IDLE state // to catch any other changes that may happen in polling. // if (m_mngr.is(IDLE)) // { // If we're checking the state in the update method, don't bother posting this here. We'll fall out of IDLE state, so any further changes // will be caught soon in polling. if (!m_checkingState) { onNativeBleStateChange(previousNativeState, newNativeState); } // m_mngr.m_stateTracker.update(E_Intent.INTENTIONAL, BleStatuses.GATT_STATUS_NOT_APPLICABLE, IDLE, false); // m_mngr.checkIdleStatus(); // } //--- > RB The below is commented out because above we are handling all states from the native callback, unless polling is currently checking //--- the state. // /*else*/ if (previousNativeState == BleStatuses.STATE_ON && newNativeState == BleStatuses.STATE_TURNING_OFF) // { // if (m_nativeState == BleStatuses.STATE_ON) // { // m_nativeState = BleStatuses.STATE_TURNING_OFF; // // //--- DRK > We allow this code path in this particular case in marshmallow because STATE_TURNING_OFF is only active // //--- for a very short time, so polling might miss it. If polling detects it before this, fine, because we // //--- early-out above and never call this method. If afterwards, it skips it because m_nativeState is identical // //--- to what's reported from the native stack. // onNativeBleStateChange(previousNativeState, newNativeState); // } // } } else { onNativeBleStateChange(previousNativeState, newNativeState); } }
Example 7
Source File: P_BluetoothCrashResolver.java From AsteroidOSSync with GNU General Public License v3.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) { if (recoveryInProgress) { if (isDebugEnabled()) Log.d(TAG, "Bluetooth discovery finished"); finishRecovery(); } else { if (isDebugEnabled()) Log.d(TAG, "Bluetooth discovery finished (external)"); } } if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED)) { if (recoveryInProgress) { discoveryStartConfirmed = true; if (isDebugEnabled()) Log.d(TAG, "Bluetooth discovery started"); } else { if (isDebugEnabled()) Log.d(TAG, "Bluetooth discovery started (external)"); } } if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); switch (state) { case BluetoothAdapter.ERROR: if (isDebugEnabled()) Log.d(TAG, "Bluetooth state is ERROR"); break; case BluetoothAdapter.STATE_OFF: if (isDebugEnabled()) Log.d(TAG, "Bluetooth state is OFF"); lastBluetoothOffTime = new Date().getTime(); break; case BluetoothAdapter.STATE_TURNING_OFF: break; case BluetoothAdapter.STATE_ON: if (isDebugEnabled()) Log.d(TAG, "Bluetooth state is ON"); if (isDebugEnabled()) Log.d(TAG, "Bluetooth was turned off for "+(lastBluetoothTurningOnTime - lastBluetoothOffTime)+" milliseconds"); if (lastBluetoothTurningOnTime - lastBluetoothOffTime < SUSPICIOUSLY_SHORT_BLUETOOTH_OFF_INTERVAL_MILLIS) { crashDetected(); } break; case BluetoothAdapter.STATE_TURNING_ON: lastBluetoothTurningOnTime = new Date().getTime(); if (isDebugEnabled()) Log.d(TAG, "Bluetooth state is TURNING_ON"); break; } } }
Example 8
Source File: P_BleManager_Listeners.java From SweetBlue with GNU General Public License v3.0 | 4 votes |
final void onNativeBleStateChangeFromBroadcastReceiver(Context context, Intent intent) { final int previousNativeState = intent.getExtras().getInt(BluetoothAdapter.EXTRA_PREVIOUS_STATE); final int newNativeState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); int logLevel = newNativeState == BluetoothAdapter.ERROR || previousNativeState == BluetoothAdapter.ERROR ? Log.WARN : Log.INFO; m_mngr.getLogger().log(logLevel, "previous=" + m_mngr.getLogger().gattBleState(previousNativeState) + " new=" + m_mngr.getLogger().gattBleState(newNativeState)); if (Utils.isMarshmallow()) { //--- > RB Commenting all this logic out. It's my opinion that we should never ignore native callbacks. Granted, we also poll the native //--- state on devices running Marshmallow or higher, but there are times when polling is insufficient (we could potentially get several //--- broadcasts between update ticks). So we'll just check if we're already checking the state, if not, we filter this broadcast through //--- to the system. // If in the IDLE state, we will pass the state change through as if pre 6.0, and bump out of the IDLE state // to catch any other changes that may happen in polling. // if (m_mngr.is(IDLE)) // { // If we're checking the state in the update method, don't bother posting this here. We'll fall out of IDLE state, so any further changes // will be caught soon in polling. if (!m_checkingState) { onNativeBleStateChange(previousNativeState, newNativeState); } // m_mngr.m_stateTracker.update(E_Intent.INTENTIONAL, BleStatuses.GATT_STATUS_NOT_APPLICABLE, IDLE, false); // m_mngr.checkIdleStatus(); // } //--- > RB The below is commented out because above we are handling all states from the native callback, unless polling is currently checking //--- the state. // /*else*/ if (previousNativeState == BleStatuses.STATE_ON && newNativeState == BleStatuses.STATE_TURNING_OFF) // { // if (m_nativeState == BleStatuses.STATE_ON) // { // m_nativeState = BleStatuses.STATE_TURNING_OFF; // // //--- DRK > We allow this code path in this particular case in marshmallow because STATE_TURNING_OFF is only active // //--- for a very short time, so polling might miss it. If polling detects it before this, fine, because we // //--- early-out above and never call this method. If afterwards, it skips it because m_nativeState is identical // //--- to what's reported from the native stack. // onNativeBleStateChange(previousNativeState, newNativeState); // } // } } else { onNativeBleStateChange(previousNativeState, newNativeState); } }
Example 9
Source File: P_BluetoothCrashResolver.java From SweetBlue with GNU General Public License v3.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) { if (recoveryInProgress) { if (isDebugEnabled()) Log.d(TAG, "Bluetooth discovery finished"); finishRecovery(); } else { if (isDebugEnabled()) Log.d(TAG, "Bluetooth discovery finished (external)"); } } if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED)) { if (recoveryInProgress) { discoveryStartConfirmed = true; if (isDebugEnabled()) Log.d(TAG, "Bluetooth discovery started"); } else { if (isDebugEnabled()) Log.d(TAG, "Bluetooth discovery started (external)"); } } if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); switch (state) { case BluetoothAdapter.ERROR: if (isDebugEnabled()) Log.d(TAG, "Bluetooth state is ERROR"); break; case BluetoothAdapter.STATE_OFF: if (isDebugEnabled()) Log.d(TAG, "Bluetooth state is OFF"); lastBluetoothOffTime = new Date().getTime(); break; case BluetoothAdapter.STATE_TURNING_OFF: break; case BluetoothAdapter.STATE_ON: if (isDebugEnabled()) Log.d(TAG, "Bluetooth state is ON"); if (isDebugEnabled()) Log.d(TAG, "Bluetooth was turned off for "+(lastBluetoothTurningOnTime - lastBluetoothOffTime)+" milliseconds"); if (lastBluetoothTurningOnTime - lastBluetoothOffTime < SUSPICIOUSLY_SHORT_BLUETOOTH_OFF_INTERVAL_MILLIS) { crashDetected(); } break; case BluetoothAdapter.STATE_TURNING_ON: lastBluetoothTurningOnTime = new Date().getTime(); if (isDebugEnabled()) Log.d(TAG, "Bluetooth state is TURNING_ON"); break; } } }
Example 10
Source File: BluetoothCrashResolver.java From android-beacon-library with Apache License 2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) { if (recoveryInProgress) { LogManager.d(TAG, "Bluetooth discovery finished"); finishRecovery(); } else { LogManager.d(TAG, "Bluetooth discovery finished (external)"); } } if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED)) { if (recoveryInProgress) { discoveryStartConfirmed = true; LogManager.d(TAG, "Bluetooth discovery started"); } else { LogManager.d(TAG, "Bluetooth discovery started (external)"); } } if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); switch (state) { case BluetoothAdapter.ERROR: LogManager.d(TAG, "Bluetooth state is ERROR"); break; case BluetoothAdapter.STATE_OFF: LogManager.d(TAG, "Bluetooth state is OFF"); lastBluetoothOffTime = SystemClock.elapsedRealtime(); break; case BluetoothAdapter.STATE_TURNING_OFF: break; case BluetoothAdapter.STATE_ON: LogManager.d(TAG, "Bluetooth state is ON"); LogManager.d(TAG, "Bluetooth was turned off for %s milliseconds", lastBluetoothTurningOnTime - lastBluetoothOffTime); if (lastBluetoothTurningOnTime - lastBluetoothOffTime < SUSPICIOUSLY_SHORT_BLUETOOTH_OFF_INTERVAL_MILLIS) { crashDetected(); } break; case BluetoothAdapter.STATE_TURNING_ON: lastBluetoothTurningOnTime = SystemClock.elapsedRealtime(); LogManager.d(TAG, "Bluetooth state is TURNING_ON"); break; } } }
Example 11
Source File: BluetoothCrashResolver.java From android-sdk with MIT License | 4 votes |
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) { if (recoveryInProgress) { if (isDebugEnabled()) Log.d(TAG, "Bluetooth discovery finished"); finishRecovery(); } else { if (isDebugEnabled()) Log.d(TAG, "Bluetooth discovery finished (external)"); } } if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED)) { if (recoveryInProgress) { discoveryStartConfirmed = true; if (isDebugEnabled()) Log.d(TAG, "Bluetooth discovery started"); } else { if (isDebugEnabled()) Log.d(TAG, "Bluetooth discovery started (external)"); } } if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); switch (state) { case BluetoothAdapter.ERROR: if (isDebugEnabled()) Log.d(TAG, "Bluetooth state is ERROR"); break; case BluetoothAdapter.STATE_OFF: if (isDebugEnabled()) Log.d(TAG, "Bluetooth state is OFF"); lastBluetoothOffTime = new Date().getTime(); break; case BluetoothAdapter.STATE_TURNING_OFF: break; case BluetoothAdapter.STATE_ON: if (isDebugEnabled()) Log.d(TAG, "Bluetooth state is ON"); if (isDebugEnabled()) Log.d(TAG, "Bluetooth was turned off for "+(lastBluetoothTurningOnTime - lastBluetoothOffTime)+" milliseconds"); if (lastBluetoothTurningOnTime - lastBluetoothOffTime < SUSPICIOUSLY_SHORT_BLUETOOTH_OFF_INTERVAL_MILLIS) { crashDetected(); } break; case BluetoothAdapter.STATE_TURNING_ON: lastBluetoothTurningOnTime = new Date().getTime(); if (isDebugEnabled()) Log.d(TAG, "Bluetooth state is TURNING_ON"); break; } } }