Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EXTRA_PREVIOUS_SCAN_MODE always returns an error for Android Bluetooth

I'm using the following code to return an object to Cordova when the device's Bluetooth's scan mode changes (i.e. discoverable/not discoverable).

cordova.getActivity().getApplicationContext().registerReceiver(new BroadcastReceiver(){
    @Override
    public void onReceive(Context c,Intent intent){
        JSONObject json=new JSONObject();
        try{
            json.put("current",intent.getIntExtra(BluetoothAdapter.EXTRA_SCAN_MODE,BluetoothAdapter.ERROR));
            json.put("previous",intent.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_SCAN_MODE,BluetoothAdapter.ERROR));
        }catch(JSONException e){
        }
        PluginResult result=new PluginResult(PluginResult.Status.OK,json);
        result.setKeepCallback(true);
        discoverableCallback.sendPluginResult(result); // discoverableCallback is a callbackContext
    }
},new IntentFilter(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED));

However, intent.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_SCAN_MODE,BluetoothAdapter.ERROR) is always BluetoothAdapter.ERROR. I tried setting discoverability on and off several times consecutively and it's always BluetoothAdapter.ERROR. How do I make it return the previous scan mode?

like image 250
Leo Jiang Avatar asked May 31 '15 04:05

Leo Jiang


1 Answers

From what I see in the AOSP source , EXTRA_PREVIOUS_SCAN_MODEis never being used. So I guess the documentation from Google is wrong in this case . If you do search here results in no references in the whole source code

like image 197
nandeesh Avatar answered Sep 22 '22 01:09

nandeesh