Java Code Examples for android.bluetooth.BluetoothAdapter#getDefaultAdapter()
The following examples show how to use
android.bluetooth.BluetoothAdapter#getDefaultAdapter() .
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: 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 2
Source File: OBD2Handler.java From react-native-obd2 with MIT License | 6 votes |
public void ready() { // onStart final BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); // onResume // get Bluetooth device mPreRequisites = btAdapter != null && btAdapter.isEnabled(); if (!mPreRequisites) { mPreRequisites = btAdapter != null && btAdapter.enable(); } if (!mPreRequisites) { sendDeviceStatus(EVENTNAME_BT_STATUS, "disabled"); } else { sendDeviceStatus(EVENTNAME_BT_STATUS, "ready"); } sendDeviceStatus(EVENTNAME_OBD_STATUS, "disconnected"); }
Example 3
Source File: Help_Fragment.java From bluetooth with Apache License 2.0 | 6 votes |
public void startbt() { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { // Device does not support Bluetooth mkmsg("This device does not support bluetooth"); return; } //make sure bluetooth is enabled. if (!mBluetoothAdapter.isEnabled()) { mkmsg("There is bluetooth, but turned off"); Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } else { mkmsg("The bluetooth is ready to use."); //bluetooth is on, so list paired devices from here. querypaired(); } }
Example 4
Source File: MainMenuActivity.java From EFRConnect-android with Apache License 2.0 | 6 votes |
@Override protected void onResume() { super.onResume(); BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter != null) { isBluetoothAdapterEnabled = bluetoothAdapter.isEnabled(); } else { isBluetoothAdapterEnabled = false; } if (!isBluetoothAdapterEnabled) { showEnableBluetoothAdapterBar(); } if (!isLocationEnabled()) { showLocationDisabledBar(); } else { hideLocationDisabledBar(); } IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); registerReceiver(bluetoothAdapterStateChangeListener, filter); }
Example 5
Source File: MediaStreamingStatus.java From sdl_java_suite with BSD 3-Clause "New" or "Revised" License | 6 votes |
@SuppressLint("MissingPermission") boolean isBluetoothActuallyAvailable(){ BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if(adapter == null || !adapter.isEnabled() ){ //False positive return false; } if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH ){ int state = adapter.getProfileConnectionState(BluetoothProfile.A2DP); if(state != BluetoothAdapter.STATE_CONNECTING && state != BluetoothAdapter.STATE_CONNECTED){ //False positive return false; } } return true; }
Example 6
Source File: BCLServiceBase.java From unity-bluetooth with MIT License | 6 votes |
public BCLServiceBase(final Activity activity) { mActivity = activity; mBtAdapter = BluetoothAdapter.getDefaultAdapter(); // Check enable bluetooth if ((mBtAdapter == null) || (!mBtAdapter.isEnabled())) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); activity.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices(); if (pairedDevices.size() > 0) { for (BluetoothDevice device : pairedDevices) { mPairedDevices.add(device); } } }
Example 7
Source File: BroadcomBle.java From GizwitsBLE with Apache License 2.0 | 5 votes |
public BroadcomBle(BleService service) { mService = service; mBtAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBtAdapter == null) { mService.bleNoBtAdapter(); return; } BluetoothGattAdapter.getProfileProxy(mService, mProfileServiceListener, BluetoothGattAdapter.GATT); }
Example 8
Source File: ScanActivity.java From android with MIT License | 5 votes |
private void initBluetooth() { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { finish(); return; } if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, 2333); } }
Example 9
Source File: MainActivity.java From BluetoothStudy with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bluetoothAdapter=BluetoothAdapter.getDefaultAdapter(); initUI(); }
Example 10
Source File: SelectDeviceDialog.java From EFRConnect-android with Apache License 2.0 | 5 votes |
private void reDiscover(boolean clearCachedDiscoveries) { if (BluetoothAdapter.getDefaultAdapter() != null && !BluetoothAdapter.getDefaultAdapter().isEnabled()) { return; } startDiscovery(discovery,clearCachedDiscoveries); }
Example 11
Source File: CoreBluetoothDetector.java From RxCentralBle with Apache License 2.0 | 5 votes |
private void stopDetection() { if (BluetoothAdapter.getDefaultAdapter() != null) { try { context.unregisterReceiver(bluetoothStateReceiver); } catch (IllegalArgumentException e) { if (RxCentralLogger.isError()) { RxCentralLogger.error("stopDetection - Unregister receiver failed!"); } } } bluetoothEnabledRelay.accept(Capability.UNSUPPORTED); }
Example 12
Source File: GetDeviceInfo.java From appium-uiautomator2-server with Apache License 2.0 | 5 votes |
@Nullable private static BluetoothInfoModel extractBluetoothInfo(DeviceInfoHelper deviceInfoHelper) { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); return bluetoothAdapter == null ? null : new BluetoothInfoModel(deviceInfoHelper.toBluetoothStateString(bluetoothAdapter.getState())); }
Example 13
Source File: BluetoothBackendHelper.java From android_external_UnifiedNlpApi with Apache License 2.0 | 5 votes |
public BluetoothBackendHelper(Context context, Listener listener){ super(context); if (listener == null) throw new IllegalArgumentException("listener must not be null"); this.listener = listener; this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothBroadcastFilter.addAction(BluetoothDevice.ACTION_FOUND); bluetoothBroadcastFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED); bluetoothBroadcastFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); }
Example 14
Source File: MainActivity.java From rubik-robot with MIT License | 5 votes |
public void connectBluetooth() { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (!mBluetoothAdapter.isEnabled()) { Toast.makeText(this, "Enable Bluetooth and pair", Toast.LENGTH_LONG).show(); return; } BluetoothDevice device = mBluetoothAdapter.getRemoteDevice("98:D3:31:30:3B:D8"); for (BluetoothDevice x : mBluetoothAdapter.getBondedDevices()) { Log.d("Main", "Address: " + x.getAddress()); for (ParcelUuid uuid : x.getUuids()) { Log.d("Main", "parceluuid:" + uuid.toString()); } } try { mBluetoothAdapter.cancelDiscovery(); BluetoothSocket socket = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805f9b34fb")); socket.connect(); mRobotScheduler = new RobotScheduler(socket.getInputStream(), socket.getOutputStream(), 10); Toast.makeText(this, "Connected to arduino", Toast.LENGTH_SHORT).show(); mMapper = new SlightlyMoreAdvancedMapper(); } catch (IOException e) { Log.d("Main", "Exception connecting to bluetooth: ", e); } }
Example 15
Source File: BluetoothManager.java From libcommon with Apache License 2.0 | 4 votes |
/** * ペアリング済みのBluetooth機器一覧を取得する * @return Bluetoothに対応していないまたは無効なら空set */ @NonNull public static Set<BluetoothDevice> getBondedDevices() { final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); return ((adapter != null) && adapter.isEnabled()) ? adapter.getBondedDevices() : Collections.emptySet(); }
Example 16
Source File: BluetoothUtils.java From Android-BluetoothKit with Apache License 2.0 | 4 votes |
public static BluetoothAdapter getBluetoothAdapter() { if (mBluetoothAdapter == null) { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); } return mBluetoothAdapter; }
Example 17
Source File: ClientComponent.java From RxAndroidBle with Apache License 2.0 | 4 votes |
@Provides @Nullable static BluetoothAdapter provideBluetoothAdapter() { return BluetoothAdapter.getDefaultAdapter(); }
Example 18
Source File: BluetoothService.java From BluetoothSPPLibrary with Apache License 2.0 | 4 votes |
public BluetoothService(Context context, Handler handler) { mAdapter = BluetoothAdapter.getDefaultAdapter(); mState = BluetoothState.STATE_NONE; mHandler = handler; }
Example 19
Source File: Ble.java From Android-BLE with Apache License 2.0 | 4 votes |
private BluetoothAdapter getBluetoothAdapter(){ if (bluetoothAdapter == null){ bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); } return bluetoothAdapter; }
Example 20
Source File: BluetoothHelper.java From BluetoothHelper with GNU General Public License v3.0 | 3 votes |
/** * Connects to the remote BluetoothDevice (server). * It bootstraps the connection to the paired (bonded) device BluetoothDevice if exists.<br> * The function does return immediately, when the connection process is yet in progress, with no result.<br> * You can receive a notification when the connection process is completed attaching a BluetoothHelperListener. * As an alternative you can check the connection status with the isConnected() method described below.<br> * An onBluetoothHelperConnectionStateChanged event occurs (if listener is attached) when the connection process terminates, returning the new status of the connection. * In case of success, the class will be ready to communicate with the remote device. * @param bluetoothDevice The remote BluetoothDevice * @see android.bluetooth.BluetoothAdapter * @see android.bluetooth.BluetoothAdapter#getBondedDevices() * @see android.bluetooth.BluetoothDevice */ public void Connect(BluetoothDevice bluetoothDevice) { Log.w("myApp", "[ # ] Connect(BluetoothDevice bluetoothDevice)"); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // Find adapter if ((mBluetoothAdapter != null) && (bluetoothDevice != null)) { if (isConnected()) Disconnect(false); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // Find adapter if (mBluetoothAdapter.isEnabled()) { // Adapter found CT = new ConnectThread(bluetoothDevice); CT.start(); } } }