Example usage for android.bluetooth BluetoothAdapter STATE_TURNING_ON

List of usage examples for android.bluetooth BluetoothAdapter STATE_TURNING_ON

Introduction

In this page you can find the example usage for android.bluetooth BluetoothAdapter STATE_TURNING_ON.

Prototype

int STATE_TURNING_ON

To view the source code for android.bluetooth BluetoothAdapter STATE_TURNING_ON.

Click Source Link

Document

Indicates the local Bluetooth adapter is turning on.

Usage

From source file:Main.java

public static boolean isBluetoothOpen() throws Exception {
    int bluetoothStateCode = getBluetoothState();
    return bluetoothStateCode == BluetoothAdapter.STATE_ON
            || bluetoothStateCode == BluetoothAdapter.STATE_TURNING_ON ? true : false;
}

From source file:Main.java

static public String state2String(int state) {
    final String ON = "STATE_ON";
    final String OFF = "STATE_OFF";
    final String TURNING_ON = "STATE_TURNING_ON";
    final String TURNING_OFF = "STATE_TURNING_OFF";

    switch (state) {
    case BluetoothAdapter.STATE_ON:
        return ON;
    case BluetoothAdapter.STATE_OFF:
        return OFF;
    case BluetoothAdapter.STATE_TURNING_ON:
        return TURNING_ON;
    case BluetoothAdapter.STATE_TURNING_OFF:
        return TURNING_OFF;
    default:/*from w w  w  . j  a v  a2 s  .  c o m*/
        return UNKNOWN;
    }
}

From source file:Main.java

public static String getStateString(int state) {
    switch (state) {
    case BluetoothAdapter.STATE_CONNECTED:
        return "Connected";
    case BluetoothAdapter.STATE_CONNECTING:
        return "Connecting";
    case BluetoothAdapter.STATE_DISCONNECTED:
        return "Disconnected";
    case BluetoothAdapter.STATE_DISCONNECTING:
        return "Disconnecting";
    case BluetoothAdapter.STATE_OFF:
        return "Off";
    case BluetoothAdapter.STATE_ON:
        return "On";
    case BluetoothAdapter.STATE_TURNING_OFF:
        return "Turning Off";
    case BluetoothAdapter.STATE_TURNING_ON:
        return "Turning On";
    default://  w  ww .java2s.  c o  m
        return "Unknown";
    }
}

From source file:org.deviceconnect.android.deviceplugin.sphero.setting.fragment.DeviceSelectionPageFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    isThreadRunning = true;//from  www .  j  av a  2  s  . c  o m
    new Thread(new Runnable() {
        @Override
        public void run() {
            BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
            if (mBluetoothAdapter == null) {
                return;
            }
            int prevState = mBluetoothAdapter.getState();
            while (isThreadRunning) {
                if (prevState != mBluetoothAdapter.getState()) {
                    if ((mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON)
                            && (prevState == BluetoothAdapter.STATE_TURNING_ON
                                    || prevState == BluetoothAdapter.STATE_OFF)) {
                        threadHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                stopDiscovery();
                                startDiscovery();
                            }
                        });
                    }
                    prevState = mBluetoothAdapter.getState();
                }

                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }).start();
}

From source file:pl.mrwojtek.sensrec.app.HeartRateDialog.java

public void onBluetoothAdapterState(int state) {
    switch (state) {
    case BluetoothAdapter.STATE_OFF:
        scanLeDevice(false);// ww  w  .  ja va2s.c o m
        break;
    case BluetoothAdapter.STATE_TURNING_OFF:
        // Ignore for now
        break;
    case BluetoothAdapter.STATE_ON:
        scanLeDevice(true);
        break;
    case BluetoothAdapter.STATE_TURNING_ON:
        // Ignore for now
        break;
    }
}

From source file:is.hello.buruberi.bluetooth.stacks.android.NativeBluetoothStack.java

@Override
@RequiresPermission(allOf = { Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN, })
public Observable<Void> turnOn() {
    if (adapter == null) {
        return Observable.error(new ChangePowerStateException());
    }/*  w w w  .  j  av  a 2  s. c  om*/

    final ReplaySubject<Void> turnOnMirror = ReplaySubject.createWithSize(1);
    final BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final int oldState = intent.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE,
                    BluetoothAdapter.ERROR);
            final int newState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
            if (oldState == BluetoothAdapter.STATE_OFF && newState == BluetoothAdapter.STATE_TURNING_ON) {
                logger.info(LOG_TAG, "Bluetooth turning on");
            } else if (oldState == BluetoothAdapter.STATE_TURNING_ON && newState == BluetoothAdapter.STATE_ON) {
                logger.info(LOG_TAG, "Bluetooth turned on");

                applicationContext.unregisterReceiver(this);

                turnOnMirror.onNext(null);
                turnOnMirror.onCompleted();
            } else {
                logger.info(LOG_TAG, "Bluetooth failed to turn on");

                applicationContext.unregisterReceiver(this);

                turnOnMirror.onError(new ChangePowerStateException());
            }
        }
    };
    applicationContext.registerReceiver(receiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
    if (!adapter.enable()) {
        applicationContext.unregisterReceiver(receiver);
        return Observable.error(new ChangePowerStateException());
    }

    return turnOnMirror;
}

From source file:com.commontime.plugin.LocationManager.java

private void initBluetoothListener() {

    //check access
    if (!hasBlueToothPermission()) {
        debugWarn("Cannot listen to Bluetooth service when BLUETOOTH permission is not added");
        return;//from   w  w w  .  ja  v a2 s  . c  o m
    }

    //check device support
    try {
        iBeaconManager.checkAvailability();
    } catch (Exception e) {
        //if device does not support iBeacons an error is thrown
        debugWarn("Cannot listen to Bluetooth service: " + e.getMessage());
        return;
    }

    if (broadcastReceiver != null) {
        debugWarn("Already listening to Bluetooth service, not adding again");
        return;
    }

    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();

            // Only listen for Bluetooth server changes
            if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {

                final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
                final int oldState = intent.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE,
                        BluetoothAdapter.ERROR);

                debugLog("Bluetooth Service state changed from " + getStateDescription(oldState) + " to "
                        + getStateDescription(state));

                switch (state) {
                case BluetoothAdapter.ERROR:
                    beaconServiceNotifier.didChangeAuthorizationStatus("AuthorizationStatusNotDetermined");
                    break;
                case BluetoothAdapter.STATE_OFF:
                case BluetoothAdapter.STATE_TURNING_OFF:
                    if (oldState == BluetoothAdapter.STATE_ON)
                        beaconServiceNotifier.didChangeAuthorizationStatus("AuthorizationStatusDenied");
                    break;
                case BluetoothAdapter.STATE_ON:
                    beaconServiceNotifier.didChangeAuthorizationStatus("AuthorizationStatusAuthorized");
                    break;
                case BluetoothAdapter.STATE_TURNING_ON:
                    break;
                }
            }
        }

        private String getStateDescription(int state) {
            switch (state) {
            case BluetoothAdapter.ERROR:
                return "ERROR";
            case BluetoothAdapter.STATE_OFF:
                return "STATE_OFF";
            case BluetoothAdapter.STATE_TURNING_OFF:
                return "STATE_TURNING_OFF";
            case BluetoothAdapter.STATE_ON:
                return "STATE_ON";
            case BluetoothAdapter.STATE_TURNING_ON:
                return "STATE_TURNING_ON";
            }
            return "ERROR" + state;
        }
    };

    // Register for broadcasts on BluetoothAdapter state change
    IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    cordova.getActivity().registerReceiver(broadcastReceiver, filter);
}

From source file:ac.robinson.bettertogether.hotspot.HotspotManagerService.java

private void initialiseHotspots(@Nullable ConnectionOptions connectionOptions)
        throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {

    mHotspotMode = true;//w w w. jav  a2s.  co  m

    if (CREATE_WIFI_HOTSPOT_SUPPORTED) {
        configureAndStartWifiHotspot(connectionOptions);
    }

    switch (mBluetoothAdapter.getState()) {
    case BluetoothAdapter.STATE_ON:
        configureAndStartBluetoothHotspot(connectionOptions);
        break;

    case BluetoothAdapter.STATE_TURNING_ON:
        break; // finish configuration in receiver

    case BluetoothAdapter.STATE_TURNING_OFF:
    case BluetoothAdapter.STATE_OFF:
    default:
        mBluetoothAdapter.enable(); // finish configuration in receiver
    }
}

From source file:io.v.android.impl.google.discovery.plugins.ble.Driver.java

public synchronized String debugString() {
    if (mBluetoothAdapter == null) {
        return "Not available";
    }//from  ww w.j a va 2 s.c o m
    StringBuilder b = new StringBuilder().append("BluetoothAdapter: ");
    switch (mBluetoothAdapter.getState()) {
    case BluetoothAdapter.STATE_ON:
        b.append("ON");
        break;
    case BluetoothAdapter.STATE_TURNING_ON:
        b.append("Turning on");
        break;
    case BluetoothAdapter.STATE_OFF:
        b.append("OFF");
        break;
    case BluetoothAdapter.STATE_TURNING_OFF:
        b.append("Turning off");
        break;
    default:
        b.append("Unknown state");
        break;
    }
    b.append("\n");
    b.append("ENABLED: ").append(mEnabled).append("\n");
    if (mServices.size() > 0) {
        b.append("ADVERTISING ").append(mServices.size()).append(" services\n");
    }
    if (mLeScanCallback != null) {
        b.append("SCANNING\n");
    }
    b.append("OnServiceReadCallbacks: ").append(mOnServiceReadCallbacks).append("\n");
    return b.toString();
}

From source file:git.egatuts.nxtremotecontroller.activity.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    final MainActivity self = this;
    super.onCreate(savedInstanceState);
    super.setActiveTheme(super.getPreferenceTheme());
    super.setContentView(R.layout.main_layout);
    toolbar = (Toolbar) super.findViewById(R.id.toolbar);
    this.setSupportToolbar();
    this.drawerFragment = (NavigationDrawerFragment) fragmentManager.findFragmentById(R.id.drawer_fragment);
    this.drawerFragment.setup(R.id.drawer_fragment, (DrawerLayout) super.findViewById(R.id.drawer_element),
            this.toolbar);
    this.appKillerReceiver = new AppKillerReceiver(this, new AppKillerListener() {
        @Override/*  w  w  w. j  a v a  2 s  .co  m*/
        public void onAppNeedsRestart(Context context, Intent intent) {
            self.selfDestroyed = true;
            self.finish();
        }
    });
    this.progressDialogOnDismiss = new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            self.getShortProgressDialog().setOnDismissListener(null);
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    self.replaceFragmentWith(self.selectedFragment, self.activeFragment);
                }
            }, 200);
        }
    };
    this.bluetoothEnableReceiver = new BluetoothEnableReceiver(this, new BluetoothEnableListener() {
        @Override
        public void onStateChange(Context context, Intent intent) {
            int state = (int) self.bluetoothEnableReceiver.getIntentData(intent);
            final BaseIndeterminateProgressDialog progress = self.getShortProgressDialog();
            Integer text = null;
            int hasToChange = 0;
            boolean hasToShow = false;

            /*
             *  We define if we have to change the fragment or we have to show a progress dialog.
             */
            switch (state) {
            case BluetoothAdapter.STATE_OFF:
                hasToChange = 2;
                break;
            case BluetoothAdapter.STATE_ON:
                hasToChange = 1;
                break;
            case BluetoothAdapter.STATE_TURNING_OFF:
                hasToShow = true;
                text = R.string.bluetooth_disabling;
                break;
            case BluetoothAdapter.STATE_TURNING_ON:
                hasToShow = true;
                text = R.string.bluetooth_enabling;
                break;
            }

            /*
             *  Here we have to show a progress dialog indicating that the bluetooth state is changing.
             */
            if (hasToShow && text != null) {
                self.showingTime = System.currentTimeMillis();
                progress.show();
                progress.setText(text);
            } else if (hasToChange != 0) {
                if (hasToChange == 1)
                    self.selectedFragment = self.lastFragment;
                if (hasToChange == 2)
                    self.selectedFragment = new BluetoothFragment();
                if (!hasToShow && progress.isShowing()) {
                    progress.setOnDismissListener(self.progressDialogOnDismiss);
                    if (System.currentTimeMillis() - self.showingTime < 500) {
                        new Handler().postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                progress.dismiss();
                            }
                        }, 750);
                    } else {
                        progress.dismiss();
                    }
                }
            }
        }
    });
    this.rippleViewListener = new RippleView.AnimationFinishListener() {
        @Override
        public void onFinish() {
            self.startControlDevice(self.controlIntent);
        }
    };
}