当设备的蓝牙扫描模式更改(即可发现/不可发现)时,我使用以下代码将对象返回到 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
。如何让它返回之前的扫描模式?
从我所看到的AOSP http://androidxref.com/5.1.0_r1/xref/packages/apps/Bluetooth/src/com/android/bluetooth/btservice/AdapterProperties.java来源 ,EXTRA_PREVIOUS_SCAN_MODE
从未被使用过。所以我猜谷歌的文档在这种情况下是错误的。如果你进行搜索导致整个源代码中没有引用
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)