本文介绍了如何使蓝牙变得不可发现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经学习了使蓝牙在Android中可发现的代码,例如:
I have learned the codes to make blue-tooth discoverable in Android,like:
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300); startActivity(discoverableIntent);` =那么,如何在发现蓝牙后就立即人工使其无法被发现?
So, how can i make blue-tooth un-discoverable artificially as soon as i make it discoverable?
感谢所有帮助!
推荐答案我找到了一个方法,尽管我还不了解,但它在我的项目中有效!
I have found a method,although i don't understand it yet,it works in my project!
public void closeDiscoverableTimeout() { BluetoothAdapter adapter=BluetoothAdapter.getDefaultAdapter(); try { Method setDiscoverableTimeout = BluetoothAdapter.class.getMethod("setDiscoverableTimeout", int.class); setDiscoverableTimeout.setAccessible(true); Method setScanMode =BluetoothAdapter.class.getMethod("setScanMode", int.class,int.class); setScanMode.setAccessible(true); setDiscoverableTimeout.invoke(adapter, 1); setScanMode.invoke(adapter, BluetoothAdapter.SCAN_MODE_CONNECTABLE,1); } catch (Exception e) { e.printStackTrace(); } }更多推荐
如何使蓝牙变得不可发现?
发布评论