EXTRA_PREVIOUS_SCAN_MODE始终为Android蓝牙返回错误

时间:2015-05-31 04:40:51

标签: android cordova bluetooth

当设备的蓝牙扫描模式发生变化(即可发现/不可发现)时,我正在使用以下代码将对象返回到Cordova。

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));

但是,intent.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_SCAN_MODE,BluetoothAdapter.ERROR)始终是BluetoothAdapter.ERROR。我尝试连续多次打开和关闭可发现性,并始终BluetoothAdapter.ERROR。如何让它返回先前的扫描模式?

1 个答案:

答案 0 :(得分:2)

根据我在AOSP来源中看到的内容,EXTRA_PREVIOUS_SCAN_MODE永远不会被使用。所以我想谷歌的文档在这种情况下是错误的。如果您在整个源代码中搜索here结果中没有引用