List of usage examples for android.bluetooth BluetoothAdapter getDefaultAdapter
public static synchronized BluetoothAdapter getDefaultAdapter()
From source file:Main.java
/** * Determine if bluetooth is turned on.//from w w w . j a va 2 s . c o m * * @return True if bloetuuth is turned on. */ public static boolean isBluetoothOn() { final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); return bluetoothAdapter.isEnabled(); }
From source file:Main.java
public static void initBluetooth(Context context) { // Get local Bluetooth adapter if (mBluetoothAdapter == null) mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); mContext = context;//from w ww . ja v a 2 s .co m }
From source file:Main.java
public static BluetoothAdapter getAdapter() { return BluetoothAdapter.getDefaultAdapter(); }
From source file:Main.java
public static boolean isBluetoothEnabled(Context context) { if (checkPermission(context, Manifest.permission.BLUETOOTH)) { BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter != null) { return mBluetoothAdapter.isEnabled(); }//w ww. ja v a 2s. c o m } return false; }
From source file:Main.java
public static void unpairMac(String macToRemove) { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); Set<BluetoothDevice> bondedDevices = bluetoothAdapter.getBondedDevices(); try {//from w w w .j a v a 2s.c om Class<?> btDeviceInstance = Class.forName(BluetoothDevice.class.getCanonicalName()); Method removeBondMethod = btDeviceInstance.getMethod("removeBond"); boolean cleared = false; for (BluetoothDevice bluetoothDevice : bondedDevices) { String mac = bluetoothDevice.getAddress(); if (mac.equals(macToRemove)) { removeBondMethod.invoke(bluetoothDevice); Log.i(TAG, "Cleared Pairing"); cleared = true; break; } } if (!cleared) { Log.i(TAG, "Not Paired"); } } catch (Throwable th) { Log.e(TAG, "Error pairing", th); } }
From source file:Main.java
public static BluetoothAdapter getBluetoothAdapter() { if (mBluetoothAdapter == null) { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); }// w w w. j av a 2 s .c om return mBluetoothAdapter; }
From source file:Main.java
public static int getBluetoothState() throws Exception { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null) { throw new Exception("bluetooth device not found!"); } else {//from ww w . j a v a 2s . com return bluetoothAdapter.getState(); } }
From source file:Main.java
public static boolean hasBluetoothAdapter() { return BluetoothAdapter.getDefaultAdapter() != null; }
From source file:Main.java
public static boolean isBluetoothAvailable() { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (!adapter.isEnabled()) { if (adapter.getState() == BluetoothAdapter.STATE_OFF) { adapter.enable();/*from w w w. j a v a2 s. co m*/ } } return adapter.getState() == BluetoothAdapter.STATE_ON; }
From source file:Main.java
static BluetoothAdapter getBluetoothAdapter() { return BluetoothAdapter.getDefaultAdapter(); }