This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

start stop scanning in android app

Hi

How to start and stop scanning continuously in android devices ?.I found that In Nrf master control panel android app there is an option of performing scanning such that it can display the dynamic data that nrf51822 is advertising (settings->scanner->continuous scanning disabled). I couldnt find this function in the source code of nrftoolbox that nordic had provided . Am developing an app for nrf51822 such that ,it advertises dynamic data which should be display live in the app( for ex.displaying rssi value). So when will they provide the source code for master control panel ? Do anybody have the function for this ?

private void scanLeDevice(final boolean enable) {

    if (enable) {
        // Stops scanning after a pre-defined scan period.
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mScanning = false;
                mBluetoothAdapter.stopLeScan(mLeScanCallback);
                System.out.println("hello");
                invalidateOptionsMenu();
            }
        }, SCAN_PERIOD);
               mScanning = true;
        mBluetoothAdapter.startLeScan(mLeScanCallback);
    } else {
        mScanning = false;
        mBluetoothAdapter.stopLeScan(mLeScanCallback);
    }
    invalidateOptionsMenu();
}

Thankyou

Parents
  • Hi Hrg,

    Actually you can find the code that we limit the period of scanning in nRFToolbox at function startScan() in ScannerFragment.java file.

    We used a timer and defined a period SCAN_DURATION to stop scanning.

    The reason we do this is to avoid continuous scanning (that can draw lots of power of the phone) when the app is in background or when the customer forgot to stop scanning.

  • Hi Hrg,

    I am now reminded that we had the issue with Nexus 4 and Nexus 7 that it only notify with LEScancallback() only once per scan. I guess you has one of this phone ?

    You are correct that we (in the MCP) stop and start scanning every one second. I was wrong about this.

    But it's pretty strange what you reported that if you do it automatically using a timer, it won't work, but if you do it manually it worked. Could you please update the code snippet where you do that scanning? Please add that code in the question you post above.

    I will try to get the developer who made the nRF MCP to help you.

Reply
  • Hi Hrg,

    I am now reminded that we had the issue with Nexus 4 and Nexus 7 that it only notify with LEScancallback() only once per scan. I guess you has one of this phone ?

    You are correct that we (in the MCP) stop and start scanning every one second. I was wrong about this.

    But it's pretty strange what you reported that if you do it automatically using a timer, it won't work, but if you do it manually it worked. Could you please update the code snippet where you do that scanning? Please add that code in the question you post above.

    I will try to get the developer who made the nRF MCP to help you.

Children
No Data
Related