当设备的蓝牙扫描模式发生变化(即可发现/不可发现)时,我正在使用以下代码将对象返回到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
。如何让它返回先前的扫描模式?