List of usage examples for android.bluetooth BluetoothAdapter STATE_OFF
int STATE_OFF
To view the source code for android.bluetooth BluetoothAdapter STATE_OFF.
Click Source Link
From source file:com.duy.pascal.interperter.libraries.android.connection.bluetooth.AndroidBluetoothLib.java
@SuppressWarnings("unused") @PascalMethod(description = "Gets the scan mode for the local dongle.\r\n" + "Return values:\r\n" + "\t-1 when Bluetooth is disabled.\r\n" + "\t0 if non discoverable and non connectable.\r\n" + "\r1 connectable non discoverable." + "\r3 connectable and discoverable.") public int bluetoothGetScanMode() { if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_OFF || mBluetoothAdapter.getState() == BluetoothAdapter.STATE_TURNING_OFF) { return -1; }// w ww .j a v a 2 s.c o m switch (mBluetoothAdapter.getScanMode()) { case BluetoothAdapter.SCAN_MODE_NONE: return 0; case BluetoothAdapter.SCAN_MODE_CONNECTABLE: return 1; case BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE: return 3; default: return mBluetoothAdapter.getScanMode() - 20; } }
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;//ww w . ja v a 2 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.j av a2s .c o 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"; }// w w w. jav a 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 av 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); } }; }
From source file:ac.robinson.bettertogether.hotspot.HotspotManagerService.java
private void connectBluetoothHotspot(@NonNull ConnectionOptions options) { Log.d(TAG, "Attempting connection via Bluetooth"); switch (mBluetoothAdapter.getState()) { case BluetoothAdapter.STATE_ON: Log.d(TAG, "Starting Bluetooth discovery"); mBluetoothAdapter.cancelDiscovery(); mBluetoothAdapter.startDiscovery(); setBluetoothErrorTimeout();/*from www. j ava2 s . c om*/ break; case BluetoothAdapter.STATE_TURNING_ON: Log.d(TAG, "Waiting for Bluetooth to be enabled"); break; // start discovery in receiver case BluetoothAdapter.STATE_OFF: case BluetoothAdapter.STATE_TURNING_OFF: default: Log.d(TAG, "Enabling Bluetooth / waiting for receiver to enable"); mBluetoothAdapter.enable(); // start discovery in receiver } }
From source file:com.evothings.BLE.java
private void reset(final CordovaArgs args, final CallbackContext cc) throws JSONException { mResetCallbackContext = null;//from ww w . j av a 2 s . c om BluetoothAdapter a = BluetoothAdapter.getDefaultAdapter(); if (mScanCallbackContext != null) { a.stopLeScan(this); mScanCallbackContext = null; } int state = a.getState(); //STATE_OFF, STATE_TURNING_ON, STATE_ON, STATE_TURNING_OFF. if (state == BluetoothAdapter.STATE_TURNING_ON) { // reset in progress; wait for STATE_ON. mResetCallbackContext = cc; return; } if (state == BluetoothAdapter.STATE_TURNING_OFF) { // reset in progress; wait for STATE_OFF. mResetCallbackContext = cc; return; } if (state == BluetoothAdapter.STATE_OFF) { boolean res = a.enable(); if (res) { mResetCallbackContext = cc; } else { cc.error("enable"); } return; } if (state == BluetoothAdapter.STATE_ON) { boolean res = a.disable(); if (res) { mResetCallbackContext = cc; } else { cc.error("disable"); } return; } cc.error("Unknown state: " + state); }
From source file:org.deviceconnect.android.deviceplugin.health.fragment.HealthCareDeviceSettingsFragment.java
/** * ?????.//from w ww .j a v a 2 s. c om * @param state Bluetooth??. */ public void stateChanged(int state) { if (mBluetoothSwitch != null) { if (state == BluetoothAdapter.STATE_ON) { mBluetoothSwitch.setChecked(true); mBluetoothSwitch.setEnabled(true); } else if (state == BluetoothAdapter.STATE_OFF) { mBluetoothSwitch.setChecked(false); mBluetoothSwitch.setEnabled(true); } } if (state == BluetoothAdapter.STATE_ON) { // ???? mRootView.findViewById(R.id.text_bluetooth_settings).setVisibility(View.GONE); mRootView.findViewById(R.id.device_list_view).setVisibility(View.VISIBLE); } else if (state == BluetoothAdapter.STATE_TURNING_OFF) { if (mIsScanning) { onClickScanButton(); } // Bluetooth OFF? mRootView.findViewById(R.id.text_bluetooth_settings).setVisibility(View.VISIBLE); mRootView.findViewById(R.id.device_list_view).setVisibility(View.GONE); } }
From source file:com.plusot.senselib.SenseMain.java
@Override protected void onActivityResult(int request, int result, Intent intent) { switch (request) { case RESULT_GPS: if (result >= 0) new SleepAndWake(new SleepAndWake.Listener() { @Override/* www . j a v a 2 s . c o m*/ public void onWake() { startUpDialogs("onActivityResult,RESULT_GPS"); } }, 100); break; case RESULT_TIMESET: if (result >= 0) new SleepAndWake(new SleepAndWake.Listener() { @Override public void onWake() { checkGPS(); } }, 100); break; case RESULT_STEP1: LLog.d(Globals.TAG, CLASSTAG + ".onActivityResult: " + result); if (result >= 0) new SleepAndWake(new SleepAndWake.Listener() { @Override public void onWake() { step = 1; showPopupDialog(STEP_POPUP, VIEW_ID_BASE + viewsAdded - 1, null); } }, 100); //showPopupDialog(STEP1SETTINGS_POPUP, VIEW_ID_BASE + viewsAdded - 1, null); break; case RESULT_BLUETOOTH: BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter != null && adapter.getState() != BluetoothAdapter.STATE_OFF) { BTManager kestrel = (BTManager) Manager.managers.get(ManagerType.BLUETOOTH_MANAGER); if (kestrel != null) kestrel.init(); startActivity(true); } break; } super.onActivityResult(request, result, intent); }
From source file:com.plusot.senselib.SenseMain.java
private void checkBluetooth() { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter != null && adapter.getState() != BluetoothAdapter.STATE_OFF) { startActivity(true);//from w w w . j a v a 2s. c o m return; } new AlertDialog.Builder(SenseMain.this).setTitle(R.string.warn_nobluetooth_title) .setMessage(R.string.warn_nobluetooth_msg) .setPositiveButton(R.string.button_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { if (dialog != null) dialog.dismiss(); startActivityForResult(new Intent(Settings.ACTION_BLUETOOTH_SETTINGS), RESULT_BLUETOOTH); } }).setNegativeButton(R.string.button_no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { if (dialog != null) dialog.dismiss(); startActivity(true); } }).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { startActivity(true); } }).create().show(); }