I am the author of the blog post mentioned above. Here's how to fix your problem for Android 21+.
// Empty data byte[] manData = new byte[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // Data Mask byte[] mask = new byte[]{0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0}; // Copy UUID into data array and remove all "-" System.arraycopy(hexStringToByteArray("YOUR_UUID_TO_FILTER".replace("-","")), 0, manData, 2, 16); // Add data array to filters ScanFilter filter = new ScanFilter.Builder().setManufacturerData(76, manData, mask).build()); public static byte[] hexStringToByteArray(String s) { int len = s.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i+1), 16)); } return data; }
The problem here is that you can add UUID filtering, but this is not entirely straightforward.