Here are the examples of the java api class android.bluetooth.BluetoothManager taken from open source projects.
1. DiscoveryActivity#checkBluetoothAvailable()
Project: Gadgetbridge
File: DiscoveryActivity.java
File: DiscoveryActivity.java
private boolean checkBluetoothAvailable() { BluetoothManager bluetoothService = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); if (bluetoothService == null) { LOG.warn("No bluetooth available"); this.adapter = null; return false; } BluetoothAdapter adapter = bluetoothService.getAdapter(); if (adapter == null) { LOG.warn("No bluetooth available"); this.adapter = null; return false; } if (!adapter.isEnabled()) { LOG.warn("Bluetooth not enabled"); Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivity(enableBtIntent); this.adapter = null; return false; } this.adapter = adapter; return true; }
2. BleProfileService#onStartCommand()
Project: Android-nRF-Toolbox
File: BleProfileService.java
File: BleProfileService.java
@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS)) throw new UnsupportedOperationException("No device address at EXTRA_DEVICE_ADDRESS key"); mDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS); // notify user about changing the state to CONNECTING final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE); broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_CONNECTING); LocalBroadcastManager.getInstance(BleProfileService.this).sendBroadcast(broadcast); final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); final BluetoothAdapter adapter = bluetoothManager.getAdapter(); final BluetoothDevice device = adapter.getRemoteDevice(mDeviceAddress); mDeviceName = device.getName(); mBleManager.connect(device); return START_REDELIVER_INTENT; }
3. ScannerFragment#onCreate()
Project: Android-nRF-Toolbox
File: ScannerFragment.java
File: ScannerFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Bundle args = getArguments(); if (args.containsKey(PARAM_UUID)) { mUuid = args.getParcelable(PARAM_UUID); } final BluetoothManager manager = (BluetoothManager) getActivity().getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = manager.getAdapter(); }
4. BleProfileService#onStartCommand()
Project: Android-nRF-Toolbox
File: BleProfileService.java
File: BleProfileService.java
@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS)) throw new UnsupportedOperationException("No device address at EXTRA_DEVICE_ADDRESS key"); final Uri logUri = intent.getParcelableExtra(EXTRA_LOG_URI); mLogSession = Logger.openSession(getApplicationContext(), logUri); mDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS); Logger.i(mLogSession, "Service started"); // notify user about changing the state to CONNECTING final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE); broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_CONNECTING); LocalBroadcastManager.getInstance(BleProfileService.this).sendBroadcast(broadcast); final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); final BluetoothAdapter adapter = bluetoothManager.getAdapter(); final BluetoothDevice device = adapter.getRemoteDevice(mDeviceAddress); mDeviceName = device.getName(); onServiceStarted(); mBleManager.connect(device); return START_REDELIVER_INTENT; }
5. BeaconLollipopActivity#onCreate()
Project: accessory-samples
File: BeaconLollipopActivity.java
File: BeaconLollipopActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setProgressBarIndeterminate(true); /* * We are going to display all the device beacons that we discover * in a list, using a custom adapter implementation */ ListView list = new ListView(this); mAdapter = new BeaconAdapter(this); list.setAdapter(mAdapter); setContentView(list); /* * Bluetooth in Android 4.3+ is accessed via the BluetoothManager, rather than * the old static BluetoothAdapter.getInstance() */ BluetoothManager manager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); mBluetoothAdapter = manager.getAdapter(); mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner(); mBeacons = new HashMap<String, TemperatureBeacon>(); }
6. BeaconKitKatActivity#onCreate()
Project: accessory-samples
File: BeaconKitKatActivity.java
File: BeaconKitKatActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setProgressBarIndeterminate(true); /* * We are going to display all the device beacons that we discover * in a list, using a custom adapter implementation */ ListView list = new ListView(this); mAdapter = new BeaconAdapter(this); list.setAdapter(mAdapter); setContentView(list); /* * Bluetooth in Android 4.3 is accessed via the BluetoothManager, rather than * the old static BluetoothAdapter.getInstance() */ BluetoothManager manager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); mBluetoothAdapter = manager.getAdapter(); mBeacons = new HashMap<String, TemperatureBeacon>(); }
7. AdvertiserActivity#onCreate()
Project: accessory-samples
File: AdvertiserActivity.java
File: AdvertiserActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_advertiser); mCurrentValue = (TextView) findViewById(R.id.current); mSlider = (SeekBar) findViewById(R.id.slider); mSlider.setMax(100); mSlider.setOnSeekBarChangeListener(this); mSlider.setProgress(DEFAULT_VALUE); /* * Bluetooth in Android 4.3+ is accessed via the BluetoothManager, rather than * the old static BluetoothAdapter.getInstance() */ BluetoothManager manager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); mBluetoothAdapter = manager.getAdapter(); mBluetoothLeAdvertiser = mBluetoothAdapter.getBluetoothLeAdvertiser(); }
8. BluetoothScan#onCreate()
Project: xDrip
File: BluetoothScan.java
File: BluetoothScan.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bluetooth_scan); ListView lv = (ListView) findViewById(android.R.id.list); final BluetoothManager bluetooth_manager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); bluetooth_adapter = bluetooth_manager.getAdapter(); mHandler = new Handler(); if (bluetooth_adapter == null) { Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_LONG).show(); has_bluetooth = false; finish(); return; } else { has_bluetooth = true; } if (bluetooth_manager == null) { Toast.makeText(this, "This device does not seem to support bluetooth", Toast.LENGTH_LONG).show(); } else { if (!bluetooth_manager.getAdapter().isEnabled()) { Toast.makeText(this, "Bluetooth is turned off on this device currently", Toast.LENGTH_LONG).show(); } else { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) { Toast.makeText(this, "The android version of this device is not compatible with Bluetooth Low Energy", Toast.LENGTH_LONG).show(); } } } mLeDeviceListAdapter = new LeDeviceListAdapter(); setListAdapter(mLeDeviceListAdapter); }
9. PhysicalWebBroadcastService#onCreate()
Project: physical-web
File: PhysicalWebBroadcastService.java
File: PhysicalWebBroadcastService.java
///////////////////////////////// // callbacks ///////////////////////////////// @Override public void onCreate() { super.onCreate(); Log.d(TAG, "SERVICE onCreate"); BluetoothManager bluetoothManager = (BluetoothManager) getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothLeAdvertiser = bluetoothManager.getAdapter().getBluetoothLeAdvertiser(); mNotificationManager = NotificationManagerCompat.from(this); }
10. BroadcastActivity#hasBleAdvertiseCapability()
Project: physical-web
File: BroadcastActivity.java
File: BroadcastActivity.java
// Check if the given bluetooth hardware // on the current device supports ble advertisemetns @TargetApi(21) private boolean hasBleAdvertiseCapability() { BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (bluetoothManager.getAdapter().getBluetoothLeAdvertiser() == null) { Log.d(TAG, "cant advertise"); return false; } Log.d(TAG, "can advertise"); return true; }
11. BroadcastActivity#checkIfBluetoothIsEnabled()
Project: physical-web
File: BroadcastActivity.java
File: BroadcastActivity.java
// Check if bluetooth is on private boolean checkIfBluetoothIsEnabled() { BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter(); if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { Log.d(TAG, "not enabled"); return false; } Log.d(TAG, "enabled"); return true; }
12. BeaconConfigFragment#initializeBluetooth()
Project: physical-web
File: BeaconConfigFragment.java
File: BeaconConfigFragment.java
private void initializeBluetooth() { // Initializes a Bluetooth adapter. For API version 18 and above, // get a reference to BluetoothAdapter through BluetoothManager. final BluetoothManager bluetoothManager = (BluetoothManager) getActivity().getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); }
13. NebDeviceListActivity#onCreate()
Project: neblina-android
File: NebDeviceListActivity.java
File: NebDeviceListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_nebdevice_list); final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); toolbar.setTitle(getTitle()); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show(); } }); View recyclerView = findViewById(R.id.nebdevice_list); assert recyclerView != null; setupRecyclerView((RecyclerView) recyclerView); scanLeDevice(true); if (findViewById(R.id.nebdevice_detail_container) != null) { // The detail container view will be present only in the // large-screen layouts (res/values-w900dp). // If this view is present, then the // activity should be in two-pane mode. mTwoPane = true; } }
14. MainActivity#onCreate()
Project: inode-client
File: MainActivity.java
File: MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Prompt for permissions if (Build.VERSION.SDK_INT >= 23) { if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Log.w("BleActivity", "Location access not granted!"); ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, MY_PERMISSION_RESPONSE); } } // selectively disable BLE-related features. if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, "BLE not supported", Toast.LENGTH_SHORT).show(); finish(); } // Initializes a Bluetooth adapter. For API level 18 and above, get a reference to // BluetoothAdapter through BluetoothManager. final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter mBluetoothAdapter = bluetoothManager.getAdapter(); // Checks if Bluetooth is supported on the device. if (mBluetoothAdapter == null) { Toast.makeText(this, "Bluetooth not supported", Toast.LENGTH_SHORT).show(); finish(); return; } Intent gattServiceIntent = new Intent(this, INodeService.class); bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE); }
15. U#getBluetoothAdapter()
Project: beacon-keeper
File: U.java
File: U.java
public static BluetoothAdapter getBluetoothAdapter(Context ctx) { BluetoothManager bm = getBluetoothManager(ctx); return (bm != null) ? bm.getAdapter() : null; }
16. BleProfileServiceReadyActivity#isBLEEnabled()
Project: Android-nRF-Toolbox
File: BleProfileServiceReadyActivity.java
File: BleProfileServiceReadyActivity.java
protected boolean isBLEEnabled() { final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothAdapter adapter = bluetoothManager.getAdapter(); return adapter != null && adapter.isEnabled(); }
17. BleProfileExpandableListActivity#isBLEEnabled()
Project: Android-nRF-Toolbox
File: BleProfileExpandableListActivity.java
File: BleProfileExpandableListActivity.java
protected boolean isBLEEnabled() { final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothAdapter adapter = bluetoothManager.getAdapter(); return adapter != null && adapter.isEnabled(); }
18. BleProfileActivity#isBLEEnabled()
Project: Android-nRF-Toolbox
File: BleProfileActivity.java
File: BleProfileActivity.java
protected boolean isBLEEnabled() { final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothAdapter adapter = bluetoothManager.getAdapter(); return adapter != null && adapter.isEnabled(); }
19. DfuActivity#isBLEEnabled()
Project: Android-nRF-Toolbox
File: DfuActivity.java
File: DfuActivity.java
private boolean isBLEEnabled() { final BluetoothManager manager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothAdapter adapter = manager.getAdapter(); return adapter != null && adapter.isEnabled(); }
20. MainActivity#onCreate()
Project: accessory-samples
File: MainActivity.java
File: MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.activity_main); setProgressBarIndeterminate(true); /* * We are going to display the results in some text fields */ mTemperature = (TextView) findViewById(R.id.text_temperature); mHumidity = (TextView) findViewById(R.id.text_humidity); mPressure = (TextView) findViewById(R.id.text_pressure); /* * Bluetooth in Android 4.3 is accessed via the BluetoothManager, rather than * the old static BluetoothAdapter.getInstance() */ BluetoothManager manager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); mBluetoothAdapter = manager.getAdapter(); mDevices = new SparseArray<BluetoothDevice>(); /* * A progress dialog will be needed while the connection process is * taking place */ mProgress = new ProgressDialog(this); mProgress.setIndeterminate(true); mProgress.setCancelable(false); }