Я пробовал this, Я могу сканировать все устройства, но не смог рассчитать основные и второстепенные с использованием основных классов Android.Как работать с Android Beacon
Я попробовал этот
public class TagBluetooth {
private Context context;
private List uuidList;
private iTagBle iTagble;
private BluetoothManager bluetoothManager;
private BluetoothAdapter bluetoothAdapter;
private BluetoothLeScanner bluetoothLeScanner;
private final int REQUEST_ENABLE_BT = 101;
private boolean mScanning;
private Handler handler;
// Stops scanning after 10 seconds.
private static final long SCAN_PERIOD = 10000;
private BluetoothAdapter.LeScanCallback leScanCallback;
private List list;
public TagBluetooth(iTagBle activity){
this.context= (Context) activity;
iTagble=activity;
}
public TagBluetooth(iTagBle activity,List list){
this.context= (Context) activity;
iTagble=activity;
uuidList=list;
}
/**
* initialize ble component
*/
public void initialize(){
if (isBLEAvailable()) {
bluetoothManager = (BluetoothManager) context.getSystemService(context.BLUETOOTH_SERVICE);
bluetoothAdapter = bluetoothManager.getAdapter();
handler = new Handler();
leScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
iTagble.onScanComplete(device,rssi,scanRecord);
}
};
}
checkBluetoothStatus();
}
/**
* Ensures Bluetooth is available on the device and it is enabled. If not,
* displays a dialog requesting user permission to enable Bluetooth.
*
* @return true for device bluetooth available and false for bluetooth not available
*/
private void checkBluetoothStatus() {
if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
context.startActivity(enableBtIntent);
}
}
/**
* ebale and disable ble devices scanning
*
* @param enable
*/
public void scanLeDevice(final boolean enable) {
if(!isBLEAvailable())
return;
if (enable) {
// Stops scanning after a pre-defined scan period.
handler.postDelayed(new Runnable() {
@Override
public void run() {
mScanning = false;
bluetoothAdapter.stopLeScan(leScanCallback);
}
}, SCAN_PERIOD);
mScanning = true;
bluetoothAdapter.startLeScan(leScanCallback);
} else {
mScanning = false;
bluetoothAdapter.stopLeScan(leScanCallback);
}
}
/**
* Use this check to determine whether BLE is supported on the device. Then
* you can selectively disable BLE-related features.
*
* @return true for BLE support and false for BLE unsupported
*/
private boolean isBLEAvailable() {
if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
iTagble.showMessage("BLE not supported");
return false;
}
return true;
}
}
Требование:
- сканирования все устройства радиомаяка (в том числе разных производителей).
- Трек входа и выхода из маяка.
- Незначительный и майор диапазона.
- Устройство сканирования даже в закрытом состоянии.
Если кто-нибудь поможет мне в этом, это будет полезно для меня. Спасибо заранее.
'Разрушен Google?' –
Что вы имеете в виду. Если у вас есть ответ, то давайте иначе оставьте его. – dmkrush
Вы являетесь членом SO с момента последнего '2 года, 11 месяцев', и вы не знаете правил SO. Plz посмотреть [Как спросить?] (Http://stackoverflow.com/help/how-to-ask) –