Search code examples
androidmobilenfcrfidproximity

How to know when another phone is 10m away from me


Let's say I want to make an android app that will be installed in 2 devices. I want to know when one device is more than 10 meters away from the other device. What type of technology will I use for that? (i.e. proximity cards, rfid, nfc, etc). And how should I go about implementing that in android, generally speaking? Thank you


Solution

  • there are few options.

    You can use Bluetooth Low Energy API and scan devices like this. You also can add another device info as filter and it will scan only this device.

    List<ScanFilter> filters = new ArrayList<> ();
    filters.add(/*create your scan filter*/);
    
    ScanSettings settings = new ScanSettings.Builder()
        .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
        .build();
    
    ScanCallback callback = new ScanCallback() {
        @Override public void onBatchScanResults(List<ScanResult> results) {
            // Do something with scan results
        }
        @Override public void onScanFailed(int errorCode) {
            // Notify error code
        }
        @Override public void onScanResult(int callbackType, ScanResult result) {
            // Do something with scan result
        }
    };
    
    mBluetoothAdapter.getBluetoothLeScanner().startScan(filters, settings, callback);
    

    Another option is to try Samsung Active 2 watches, which could scan for BLE and detect another ones. Now at Navigine we are working with them and they show pretty good results. However, you will need to write the code for Tizen OS. If you will have any questions, feel free to write us!