List of usage examples for android.bluetooth BluetoothAdapter getDefaultAdapter
public static synchronized BluetoothAdapter getDefaultAdapter()
From source file:Main.java
/** * Check if bluetooth function enabled/*from w ww.j a va2 s . co 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:Main.java
/** * Check if Bluetooth is on./* ww w . j ava 2 s. c om*/ * * @param activity the activity * @return true, if successful */ public static boolean checkBLEOn(Activity activity) { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); return adapter.isEnabled(); }
From source file:Main.java
public static final String[] getBondedDeviceNames() { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); Set<BluetoothDevice> devices = adapter.getBondedDevices(); String[] names = new String[devices.size()]; int i = 0;/* w ww .jav a 2 s .co m*/ for (BluetoothDevice d : devices) { Log.d(TAG, "Found bonded device " + d.getName()); names[i++] = d.getName(); } return names; }
From source file:Main.java
public static String getLocalAddress(Context context) { // http://stackoverflow.com/a/33749218 // http://stackoverflow.com/a/34494459 String address = ""; if (Build.VERSION.SDK_INT <= 22) { address = BluetoothAdapter.getDefaultAdapter().getAddress(); } else {/* w ww .ja v a 2 s . c om*/ address = android.provider.Settings.Secure.getString(context.getContentResolver(), "bluetooth_address"); } return address; }
From source file:Main.java
/** * Check if Bluetooth LE device supported on the running environment. * * @param context the context/* ww w. j av a2 s.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
@SuppressWarnings("MissingPermission") public static String getBluetoothMAC(Context context) { String result = null;//from ww w . j a va2 s . c om try { if (context.checkCallingOrSelfPermission( Manifest.permission.BLUETOOTH) == PackageManager.PERMISSION_GRANTED) { BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter(); result = bta.getAddress(); } } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:Main.java
public static String getMACAddress() { if ((mBluetoothAdapter != null) && (mBluetoothAdapter.isEnabled())) { return BluetoothAdapter.getDefaultAdapter().getAddress(); } else/*from w w w.j a v a2 s. c o m*/ return "00000000"; }
From source file:org.chromium.chrome.browser.physicalweb.Utils.java
public static int getBluetoothEnabledStatus() { int statusResult = RESULT_INDETERMINATE; if (isBluetoothPermissionGranted()) { BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter(); statusResult = (bt != null && bt.isEnabled()) ? RESULT_SUCCESS : RESULT_FAILURE; }//from w ww . j av a2 s . c o m return statusResult; }
From source file:com.android.tv.settings.name.DeviceManager.java
/** * Sets the system device name.//from w w w . j a va 2 s. c om * * For now it will explicitly call the different discoverable services that haven't been ported * to use the Settings.Global.DEVICE_NAME entry. * * @param context A context that can access Settings.Global * @param name The new device name. */ public static void setDeviceName(Context context, String name) { Settings.Global.putString(context.getContentResolver(), Settings.Global.DEVICE_NAME, name); BluetoothAdapter.getDefaultAdapter().setName(name); LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(ACTION_DEVICE_NAME_UPDATE)); }
From source file:Main.java
public static final String getOblyDevicesID(Context mContext) { String m_szImei = ""; try {// ww w . ja va 2 s .c om TelephonyManager TelephonyMgr = null; TelephonyMgr = (TelephonyManager) mContext.getSystemService(Activity.TELEPHONY_SERVICE); m_szImei = TelephonyMgr.getDeviceId(); } catch (Exception ex) { ex.printStackTrace(); } String m_szDevIDShort = null; try { m_szDevIDShort = "35" + //we make this look like a valid IMEI Build.BOARD.length() % 10 + Build.BRAND.length() % 10 + Build.CPU_ABI.length() % 10 + Build.DEVICE.length() % 10 + Build.DISPLAY.length() % 10 + Build.HOST.length() % 10 + Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 + Build.MODEL.length() % 10 + Build.PRODUCT.length() % 10 + Build.TAGS.length() % 10 + Build.TYPE.length() % 10 + Build.USER.length() % 10; //13 digits } catch (Exception ex) { ex.printStackTrace(); } String m_szAndroidID = ""; try { m_szAndroidID = ""; Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID); } catch (Exception ex) { ex.printStackTrace(); } String m_szWLANMAC = ""; try { WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); m_szWLANMAC = wm.getConnectionInfo().getMacAddress(); } catch (Exception ex) { ex.printStackTrace(); } String m_szBTMAC = null; try { BluetoothAdapter m_BluetoothAdapter = null; // Local Bluetooth adapter m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); m_szBTMAC = m_BluetoothAdapter.getAddress(); } catch (Exception ex) { ex.printStackTrace(); } String m_szLongID = m_szImei + m_szDevIDShort + m_szAndroidID + m_szWLANMAC + m_szBTMAC; // compute md5 MessageDigest m = null; try { m = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } m.update(m_szLongID.getBytes(), 0, m_szLongID.length()); // get md5 bytes byte p_md5Data[] = m.digest(); // create a hex string String m_szUniqueID = new String(); for (int i = 0; i < p_md5Data.length; i++) { int b = (0xFF & p_md5Data[i]); // if it is a single digit, make sure it have 0 in front (proper padding) if (b <= 0xF) m_szUniqueID += "0"; // add number to string m_szUniqueID += Integer.toHexString(b); } // hex string to uppercase m_szUniqueID = m_szUniqueID.toUpperCase(); return m_szUniqueID; }