- 浏览: 20975 次
最新评论
与蓝牙相关的API
1、BluetoothAdapter
该类的对象代表了本地的蓝牙适配器
2、BluetoothDevice
该类的对象代表了远程的蓝牙适配器
扫描已经配对的蓝牙设备步骤:
1、获得BluetoothAdapter对象
2、判断当前的设备中是否有蓝牙设备
3、判断当前设备中的蓝牙设备是否已经打开
4、得到所以已经配对的蓝牙设备对象
在AndroidManifedt.xml中声明蓝牙权限
在布局文件中添加一个按钮
main.xml
MainActivity.java
1、BluetoothAdapter
该类的对象代表了本地的蓝牙适配器
2、BluetoothDevice
该类的对象代表了远程的蓝牙适配器
扫描已经配对的蓝牙设备步骤:
1、获得BluetoothAdapter对象
2、判断当前的设备中是否有蓝牙设备
3、判断当前设备中的蓝牙设备是否已经打开
4、得到所以已经配对的蓝牙设备对象
在AndroidManifedt.xml中声明蓝牙权限
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="test.bluetooth01" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".TestBluetoothActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.BLUETOOTH"/> </manifest>
在布局文件中添加一个按钮
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:id="@+id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="扫描蓝牙设备" /> </LinearLayout>
MainActivity.java
import java.util.Iterator; import java.util.Set; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class TestBluetoothActivity extends Activity { /** Called when the activity is first created. */ private Button button = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button = (Button)findViewById(R.id.button); button.setOnClickListener(new ButtonListener()); } private class ButtonListener implements OnClickListener { @Override public void onClick(View v) { // TODO Auto-generated method stub //得到BluetoothAdapter对象 BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); //判断BluetoothAdapter对象是否为空,若为空,则本机上无蓝牙设备 if (bluetoothAdapter != null) { System.out.println("本机上拥有蓝牙设备"); if (!bluetoothAdapter.enable()) { //创建一个Intent对象,该对象用来启动另外一个Activity,提示用户启动蓝牙设备 Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivity(intent); } //得到所有已经匹配的蓝牙适配器对象 Set<BluetoothDevice> device = bluetoothAdapter.getBondedDevices(); if (device.size()>0) { for (Iterator iterator = device.iterator(); iterator .hasNext();) { BluetoothDevice bluetoothDevice = (BluetoothDevice) iterator .next(); System.out.println(bluetoothDevice.getAddress()); } } } else { System.out.println("本机上无蓝牙设备"); } } } }
发表评论
-
SQLite数据库
2011-10-21 11:12 9911。从www.sqlite.org下载SQLite 3.3.4 ... -
android中的有道词典实例
2011-10-19 22:51 8961、布局文件main.xml <?xml version ... -
mars老师的googleMap示例(二)
2011-10-15 17:14 846manifest.xml文件 <?xml version ... -
mars老师的googleMap(一)
2011-10-15 10:43 789一、申请 Apikey Apikey Apikey Apike ... -
Intent在android中的几种用法
2011-10-14 09:26 753如果是从BroadcastReceiver 启动一个新的Act ... -
基于Service与ContentProvider的音乐播放实例
2011-10-13 23:37 727Android的核心也就是Activi ... -
android之用户定位(一)
2011-10-13 19:53 16651、User Location 能做什么 1) 获取用户的位置 ... -
android之蓝牙操作(二)
2011-10-13 18:43 12711、修改本蓝牙设备的可见性 2、扫描周围可用蓝牙设备 步骤: ... -
Android学习之JSON数据解析
2011-10-12 13:30 676在Android应用开发中,常用的数据交换格式有XML和JSO ... -
android中的JSON解析
2011-10-12 10:17 8851 。 什么是JSON 就是现在网络上比较流行 ... -
Animations的使用(六)
2011-10-11 17:44 1114LayoutAnimationController的使用方法( ... -
Animations的使用(五)
2011-10-11 17:41 7021 AnimationSet的使用方法 什么是Animat ... -
Animations使用 (四)
2011-10-11 17:36 549Animations的第二种使用方法(第一种见1) 步骤: ... -
android面试
2011-10-10 21:12 762为什么要用ContentProvider?它和sql的实现上有 ... -
android中的animations的用法(三)
2011-10-10 21:07 691一 LayoutAnimationController ... -
android中的animations的用法(二)
2011-10-10 20:59 767一 AnimationSet 的用法 二 Interpol ... -
android中的animations的用法 (一)
2011-10-10 20:56 1306Animations 可分为两大类: 一 Tweened A ...
相关推荐
android平台的蓝牙读卡器操作,首先通过蓝牙连接读卡器,连接成功后,发送读卡命令,读取附近的射频卡,读卡器返回卡号后,停止读卡。
采用kotlin 对蓝牙进行打开和关闭,以及搜索蓝牙设备,与其他蓝牙设备配对,并将所有配对的信息进行显示。相关说明看 https://mp.csdn.net/mp_blog/creation/editor/119547298
Android 蓝牙BLE全面解析以及智能车锁开发实例一、蓝牙BLE产生背景——蓝牙的发展历程 二、蓝牙BLE的基本概念 三、蓝牙BLE的架构介绍 1. 蓝牙BLE架构概览 2. 简述BLE如何发送数据包 2.1 广播方式 2.2 连接方式 四、...
这个APP是通过JAVA代码来编写的,实际上就是一个通过Android Studio的编译生成的APK文件。小车蓝牙和手机端成功完成配对,使用手机APP上的键盘控制给小车发送指令,小车上的芯片收到了指令后进行处理,最后小车能够...
Android 蓝牙操作,可以用于与下位机硬件部分通信牙模块。 Android 蓝牙操作。Android 蓝牙操作。
android 简单抽取的ble蓝牙库,用于操作ble的
Android蓝牙相关操作源代码,包括蓝牙扫描、连接、通讯相关一操作.
Android蓝牙开发客户端代码,必须配合服务器端进行操作,
Android-BLE,AndroidBLE 蓝牙框架,包括扫描、连接、设置通知、发送数据、读取、接收数据和 OTA 升级以及各种直观的回调,近乎一行代码植入项目,可扩展配置蓝牙相关操作。.zip
android 蓝牙操作的demo
android 好用的ble蓝牙调试助手,方便操作,查看服务的UUID
Android Stdio开发,可以搜索蓝牙,连接蓝牙等操作
操作蓝牙的代码demo.通过demo可以基本了解蓝牙通讯的流程。
基于Android平台的一个关于应用蓝牙设备进行聊天的程序,目前程序已实现2台设备之间的通信,服务器部分是按照的一对多的方式写的```没有测试3台设备是否能聊天,不过2台设备配对后``是百分百可以的,有UI界面,操作简单,...
Android BLE 蓝牙开发框架,使用回调方式处理,搜索、连接、notify、indicate、读、写等一系列蓝牙操作
Android手机蓝牙控制,讲用android手机控制蓝牙,对蓝牙的操作和实用,简介明了,是个很好的文档
android蓝牙工具类,包括连接蓝牙,发送数据等操作
蓝牙(Bluetooth)技术是一种低成本的无线数据与数字通信的开放性全球规范。 Android 是Google 于2007 年11 月5 日宣布的基于Linux 平台开源手机操作系统名称,该平 台由操作系统、中间件、用户界面和应用软件组成,...
android操作蓝牙4.0的代码,手机端需要三星4.1.2以上系统,经过测试,三星的S3和note2都可用,蓝牙模块用的是Ti的CC2540模块,本资源包含了手机端的代码和模块的代码,欢迎广大有需要的朋友下载
Android蓝牙操作:与蓝牙串口模块通信,或其他蓝牙设备通信。这个程序虽然不是很完善,但作为二次开发是不错的选择,是一个学习蓝牙串口很好的参考,里面有注释