Java Code Examples for android.bluetooth.BluetoothAdapter#getAddress()
The following examples show how to use
android.bluetooth.BluetoothAdapter#getAddress() .
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: EasyBluetoothMod.java From easydeviceinfo with Apache License 2.0 | 6 votes |
/** * Gets Bluetooth MAC Address * * You need to declare the below permission in the manifest file to use this properly * * <uses-permission android:name="android.permission.BLUETOOTH"/> * * @return the bluetooth mac * * @deprecated */ @SuppressLint("HardwareIds") @RequiresPermission(Manifest.permission.BLUETOOTH) @Deprecated public final String getBluetoothMAC() { String result = "00:00:00:00:00:00"; if (PermissionUtil.hasPermission(context, Manifest.permission.BLUETOOTH)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { // Hardware ID are restricted in Android 6+ // https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-hardware-id // Getting bluetooth mac via reflection for devices with Android 6+ result = android.provider.Settings.Secure.getString(context.getContentResolver(), "bluetooth_address"); } else { BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter(); result = bta != null ? bta.getAddress() : result; } } return CheckValidityUtil.checkValidData(result); }
Example 2
Source File: BtUtils.java From apollo-DuerOS with Apache License 2.0 | 5 votes |
public static String getBtAddress() { String btaddr = ""; BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); if (btAdapter != null) { btaddr = btAdapter.getAddress(); if (!BluetoothAdapter.checkBluetoothAddress(btaddr)) { btaddr = ""; } } return btaddr; }
Example 3
Source File: DeviceUtil.java From AndroidStudyDemo with GNU General Public License v2.0 | 5 votes |
/** * 蓝牙MAC地址 * 需要权限 <uses-permission android:name="android.permission.BLUETOOTH "/> * @param context * @return */ private static String bluetoothMAC(Context context) { String bluetoothMACStr = ""; BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothMACStr = bluetoothAdapter.getAddress(); return bluetoothMACStr; }
Example 4
Source File: DeviceIdentifier.java From android-device-identification with Apache License 2.0 | 5 votes |
/** * getMacAddress() returns the unique bluetooth hardware address * Works only if bluetooth module is present */ @Override String getId(Context ctx) { BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter(); if (ba == null) { w("Bluetooth Adapter not available"); return null; } assertPermission(ctx, permission.BLUETOOTH); return ba.getAddress(); }
Example 5
Source File: BluetoothUtil.java From Rumble with GNU General Public License v3.0 | 5 votes |
public static String getBluetoothMacAddress() { BluetoothAdapter mBluetoothAdapter = getBluetoothAdapter(RumbleApplication.getContext()); if(mBluetoothAdapter==null) return null; return mBluetoothAdapter.getAddress(); }
Example 6
Source File: CarlifeDeviceInfoManager.java From apollo-DuerOS with Apache License 2.0 | 4 votes |
public void init() { try { CarlifeDeviceInfo.Builder builder = CarlifeDeviceInfo.newBuilder(); builder.setOs(CommonParams.TYPE_OF_OS); builder.setBoard(android.os.Build.BOARD); builder.setBootloader(android.os.Build.BOOTLOADER); builder.setBrand(android.os.Build.BRAND); builder.setCpuAbi(android.os.Build.CPU_ABI); builder.setCpuAbi2(android.os.Build.CPU_ABI2); builder.setDevice(android.os.Build.DEVICE); builder.setDisplay(android.os.Build.DISPLAY); builder.setFingerprint(android.os.Build.FINGERPRINT); builder.setHardware(android.os.Build.HARDWARE); builder.setHost(android.os.Build.HOST); builder.setCid(android.os.Build.ID); builder.setManufacturer(android.os.Build.MANUFACTURER); builder.setModel(android.os.Build.MODEL); builder.setProduct(android.os.Build.PRODUCT); builder.setSerial(android.os.Build.SERIAL); builder.setCodename(android.os.Build.VERSION.CODENAME); builder.setIncremental(android.os.Build.VERSION.INCREMENTAL); builder.setRelease(android.os.Build.VERSION.RELEASE); builder.setSdk(android.os.Build.VERSION.SDK); builder.setSdkInt(android.os.Build.VERSION.SDK_INT); BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter != null) { String addrString = mBluetoothAdapter.getAddress(); if (!TextUtils.isEmpty(addrString)) { builder.setBtaddress(addrString); } else { builder.setBtaddress("unknow"); } } else { builder.setBtaddress("unknow"); } mDeviceInfo = builder.build(); } catch (Exception ex) { LogUtil.e(TAG, "init error"); ex.printStackTrace(); } }
Example 7
Source File: Bluetooth.java From batteryhub with Apache License 2.0 | 4 votes |
@SuppressLint("HardwareIds") public static String getAddress(final Context context) { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); return (adapter != null) ? adapter.getAddress() : context.getString(R.string.not_available); }