List of usage examples for android.bluetooth BluetoothManager getAdapter
public BluetoothAdapter getAdapter()
From source file:Main.java
private static void prepareBTAdapter(final Activity activity) { // Initializes Bluetooth adapter. BluetoothManager bluetoothManager = (BluetoothManager) activity.getSystemService(Context.BLUETOOTH_SERVICE); bluetoothAdapter = bluetoothManager.getAdapter(); }
From source file:Main.java
public static BluetoothAdapter getAdapter(Context context) { // Initializes Bluetooth adapter. final BluetoothManager bluetoothManager = (BluetoothManager) context .getSystemService(Context.BLUETOOTH_SERVICE); return bluetoothManager.getAdapter(); }
From source file:Main.java
public static BluetoothAdapter getBluetoothAdapter(Context ctx) { final BluetoothManager bluetoothManager = (BluetoothManager) ctx .getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); return mBluetoothAdapter; }
From source file:Main.java
/** * Enable bluetooth and get the adapter object * @return A BluetoothAdapter instance/* w w w . j a v a 2 s . c o m*/ */ public static BluetoothAdapter getLeAdapter(Activity _this) { // Initializes Bluetooth adapter. final BluetoothManager bluetoothLeManager = (BluetoothManager) _this .getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothAdapter bluetoothLeAdapter = bluetoothLeManager.getAdapter(); // Ensures Bluetooth is available on the device and it is enabled. If not, // displays a dialog requesting user permission to mEnableCharacteristic Bluetooth. // TODO / FIXME currently this bugs if the user doesn't have BT enabled, // TODO / FIXME since it just returns null and doesn't check the result later. if (bluetoothLeAdapter == null || !bluetoothLeAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); _this.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); return null; } else { return bluetoothLeAdapter; } }
From source file:Main.java
public static Pair<BluetoothManager, BluetoothAdapter> checkBT(final Activity activity) { // Use this check to determine whether BLE is supported on the device. Then // you can selectively disable BLE-related features. if (!btleSupport(activity)) { return null; }/*w w w . j a v a2 s. co m*/ final BluetoothManager bluetoothManager = (BluetoothManager) activity .getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter(); //On some devices this does not work try { bluetoothAdapter.getBluetoothLeScanner(); } catch (NoSuchMethodError e) { return null; } // Ensures Bluetooth is available on the device and it is enabled. If not, // displays a dialog requesting user permission to enable Bluetooth. if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); activity.startActivityForResult(enableBtIntent, 1); bluetoothAdapter = bluetoothManager.getAdapter(); } return new Pair<BluetoothManager, BluetoothAdapter>(bluetoothManager, bluetoothAdapter); }
From source file:Main.java
public static BluetoothAdapter getBluetoothAdapter(Context context) { // Initializes a Bluetooth adapter. For API level 18 and above, get a reference to // BluetoothAdapter through BluetoothManager. final BluetoothManager bluetoothManager = (BluetoothManager) context .getSystemService(Context.BLUETOOTH_SERVICE); if (bluetoothManager == null) { return null; }// w w w . j ava 2 s .co m return bluetoothManager.getAdapter(); }
From source file:Main.java
/** * Check if Bluetooth LE device supported on the running environment. * * @param context the context/* w ww .ja va 2s . c o m*/ * @return true if supported */ public static boolean isBleSupported(@NonNull Context context) { try { if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) == false) { return false; } BluetoothManager bluetoothManager = (BluetoothManager) context .getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothAdapter bluetoothAdapter; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { bluetoothAdapter = bluetoothManager.getAdapter(); } else { bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); } if (bluetoothAdapter != null) { return true; } } catch (Throwable t) { // ignore exception } return false; }
From source file:Main.java
/** * Check if bluetooth function enabled// www . j a va 2 s .c o m * * @param context the context * @return true if bluetooth enabled */ public static boolean isBluetoothEnabled(@NonNull Context context) { BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE); if (bluetoothManager == null) { return false; } final BluetoothAdapter bluetoothAdapter; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { bluetoothAdapter = bluetoothManager.getAdapter(); } else { bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); } if (bluetoothAdapter == null) { return false; } return bluetoothAdapter.isEnabled(); }
From source file:com.coinblesk.client.utils.UIUtils.java
private static boolean isBluetoothEnabled(Context context) { BluetoothManager bm = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter mBluetoothAdapter = bm.getAdapter(); return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled(); }
From source file:com.coinblesk.client.utils.UIUtils.java
private static boolean hasBluetoothLEAdvertiser(Context context) { BluetoothManager bm = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter mBluetoothAdapter = bm.getAdapter(); return mBluetoothAdapter != null && mBluetoothAdapter.isMultipleAdvertisementSupported(); }