2015-06-04 148 views
-3

我试过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; 
} 

}

要求:

  1. 扫描所有的信标设备(包括不同的制造商)。
  2. 轨道进入和退出灯塔。
  3. 小和大不等。
  4. 扫描设备偶数应用程序已关闭。

如果有人帮我解决这个问题,它肯定会是我的。 在此先感谢。

+2

'Google是不是破了?' –

+0

你是什么意思..如果你有答案,那么给予否则离开它。 – dmkrush

+0

您是上一次“2年11个月”以来的成员,您不知道SO的规则。 PLZ看看[如何问?](http://stackoverflow.com/help/how-to-ask) –

回答

1

使用来自here的Kontakt API。但是你不能从任何API获得确切的进入和退出时间。请参阅here

+0

感谢您的建议。但是这是针对特定的供应商。我想它应该适用于所有供应商。 – dmkrush

+0

使用Estimote sdk。这是所有供应商的工作。我使用这个API获得了所有附近的信标列表。 https://github.com/Estimote/Android-SDK –

+0

我已经集成了Estimote SDK。它监视不同供应商的区域,但它不会给不。在一个地区的设备。 – dmkrush

相关问题