android连接蓝牙设备Bluetoot

 时间:2024-10-27 05:35:33

an蟠校盯昂droid连接蓝牙设备,可以试着两个手机进行蓝牙连接测试。复杂的连接其他蓝牙设备,我们就不说了。(因为实现通信需要发送对应的指令集)

工具/原料

编译工具:Eclipse

方法/步骤

1、先展示代码结构

android连接蓝牙设备Bluetoot

2、连接蓝牙类类名:MainActivity(有点偷懒,没有起表意的类名。)

android连接蓝牙设备Bluetoot

3、要声明的控件和变量等

android连接蓝牙设备Bluetoot

4、在onCreate声明控件

android连接蓝牙设备Bluetoot

5、ToogleButton设置开关状态声明一个组件愿意接收IntentFil隋茚粟胫terintent=newIntentFilter();

android连接蓝牙设备Bluetoot

6、BroadcastReceiver广播接收器

android连接蓝牙设备Bluetoot

android连接蓝牙设备Bluetoot

7、listview点击事件OnItemClickListenerOnClickListener

android连接蓝牙设备Bluetoot

android连接蓝牙设备Bluetoot

8、蓝牙连接

android连接蓝牙设备Bluetoot

9、退出消耗页面是的onDestroy()

android连接蓝牙设备Bluetoot

10、布局结构图<RelativeLay艺皱麾酪outxmlns:android="http://schemas.andro足毂忍珩id.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context="com.example.bluetooth_connection.MainActivity"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:orientation="horizontal"><Buttonandroid:id="@+id/btnSearch"android:layout_width="fill_parent"android:layout_height="fill_parent"android:text="搜索"android:layout_weight="1"/><Buttonandroid:id="@+id/btnExit"android:layout_width="fill_parent"android:layout_height="fill_parent"android:text="退出"android:layout_weight="1"/><Buttonandroid:id="@+id/btnDis"android:layout_width="fill_parent"android:layout_height="fill_parent"android:text="开启蓝牙"android:layout_weight="1"/></LinearLayout><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:orientation="vertical"><ToggleButtonandroid:id="@+id/tbtnSwitch"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_gravity="center_horizontal"android:textOff="关闭蓝牙"android:textOn="开启蓝牙"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="0.3"android:orientation="vertical"><ListViewandroid:id="@+id/lvDevices"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="#f1f1f1"android:cacheColorHint="#ff333333"android:fadingEdge="none"android:scrollbars="none"></ListView></LinearLayout></LinearLayout></RelativeLayout>

android连接蓝牙设备Bluetoot

11、界面效果

android连接蓝牙设备Bluetoot

12、例子如下

android连接蓝牙设备Bluetoot

windows11扫雷游戏在哪 怎么解决校园网络又慢又卡的问题 win11录屏快捷键是什么 如何让校园网网速变得更快 win11怎么显示文件扩展名
热门搜索
五星红旗的图片 小草的图片 漫画寻找前世之旅 漫画格式 鬼怪图片