如何使蓝牙变得不可发现?

编程入门 行业动态 更新时间:2024-10-26 07:34:57
本文介绍了如何使蓝牙变得不可发现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

如何使蓝牙变得不可发现?

本文发布于:2023-11-08 06:50:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568642.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:蓝牙   发现

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!