Skip navigation links
org.altbeacon.bluetooth

Class BluetoothMedic

    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static int NO_TEST
      Indicates that no test should be run by the BluetoothTestJob
      static int SCAN_TEST
      Indicates that the bluetooth scan test should be run by the BluetoothTestJob
      static int TRANSMIT_TEST
      Indicates that the transmitter test should be run by the BluetoothTestJob
    • Field Detail

      • NO_TEST

        public static final int NO_TEST
        Indicates that no test should be run by the BluetoothTestJob
        See Also:
        Constant Field Values
      • TRANSMIT_TEST

        public static final int TRANSMIT_TEST
        Indicates that the transmitter test should be run by the BluetoothTestJob
        See Also:
        Constant Field Values
      • SCAN_TEST

        public static final int SCAN_TEST
        Indicates that the bluetooth scan test should be run by the BluetoothTestJob
        See Also:
        Constant Field Values
    • Method Detail

      • getInstance

        public static BluetoothMedic getInstance()
        Get a singleton instance of the BluetoothMedic
        Returns:
      • enablePowerCycleOnFailures

        @RequiresApi(value=21)
        public void enablePowerCycleOnFailures(Context context)
        If set to true, bluetooth will be power cycled on any tests run that determine bluetooth is in a bad state.
        Parameters:
        context -
      • enablePeriodicTests

        @RequiresApi(value=21)
        public void enablePeriodicTests(Context context,
                                                               int testType)
        Calling this method starts a scheduled job that will run tests of the specified type to make sure bluetooth is OK and cycle power to bluetooth if needed and configured by enablePowerCycleOnFailures
        Parameters:
        context -
        testType - e.g. BluetoothMedic.TRANSMIT_TEST | BluetoothMedic.SCAN_TEST
      • runScanTest

        @RequiresApi(value=21)
        public boolean runScanTest(Context context)
        Starts up a brief blueooth scan with the intent of seeing if it results in an error condition indicating the bluetooth stack may be in a bad state. If the failure error code matches a pattern known to be associated with a bad bluetooth stack state, then the bluetooth stack is turned off and then back on after a short delay in order to try to recover.
        Returns:
        false if the test indicates a failure indicating a bad state of the bluetooth stack
      • runTransmitterTest

        @RequiresApi(value=21)
        public boolean runTransmitterTest(Context context)
        Starts up a beacon transmitter with the intent of seeing if it results in an error condition indicating the bluetooth stack may be in a bad state. If the failure error code matches a pattern known to be associated with a bad bluetooth stack state, then the bluetooth stack is turned off and then back on after a short delay in order to try to recover.
        Returns:
        false if the test indicates a failure indicating a bad state of the bluetooth stack
      • setNotificationsEnabled

        @RequiresApi(value=21)
        public void setNotificationsEnabled(boolean enabled,
                                                                   int icon)
        Configure whether to send user-visible notification warnings when bluetooth power is cycled.
        Parameters:
        enabled - if true, a user-visible notification is sent to tell the user when
        icon - the icon drawable to use in notifications (e.g. R.drawable.notification_icon)