当设备的蓝牙扫描模式发生变化(即可发现/不可发现)时,我使用以下代码将对象返回给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。我连续几次尝试将discoverability设置为on和off,结果总是BluetoothAdapter.ERROR。如何使其返回到以前的扫描模式?
发布于 2015-06-19 18:06:20
根据我在AOSP源代码中看到的,EXTRA_PREVIOUS_SCAN_MODE从未被使用过。所以我猜谷歌的文档在这种情况下是错误的。如果您确实要搜索here,那么整个源代码中都不会有任何引用
https://stackoverflow.com/questions/30553911
复制相似问题