如何使蓝牙变得不可发现? [英] How to make Bluetooth Undiscoverable?

查看:276
本文介绍了如何使蓝牙变得不可发现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经学习了使蓝牙在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();  
    }  
}  

这篇关于如何使蓝牙变得不可发现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆