job.answiz.com
  • 1
Votes
name

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?

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

  • 0
Reply Report