没有合适的资源?快使用搜索试试~ 我知道了~
首页android蓝牙串口编程官方指导(非常详细,PDF)
android蓝牙串口编程官方指导(非常详细,PDF)
5星 · 超过95%的资源 需积分: 50 279 下载量 141 浏览量
更新于2023-03-16
评论 11
收藏 190KB PDF 举报
android蓝牙串口的官方资料,从GOOGLE网站上打印下来的,格式还行。本人觉得是开发蓝牙最佳的参考资料。
资源详情
资源评论
资源推荐
Quickview
Android's bluetooth APIs allow your application
to perform wireless data transactions with
other devices
In this document
The Basics
Bluetooth Permissions
Setting Up Bluetooth
Finding Devices
Querying paired devices
Discovering devices
Connecting Devices
Connecting as a server
Connecting as a client
Managing a Connection
Working with Profiles
Vendor-specific AT commands
Health Device Profile
Key classes
BluetoothAdapter
BluetoothDevice
BluetoothSocket
BluetoothServerSocket
Related samples
Bluetooth Chat
Bluetooth HDP (Health Device Profile)
The Android platform includes support for the Bluetooth
network stack, which allows a device to wirelessly exchange
data with other Bluetooth devices. The application
framework provides access to the Bluetooth functionality
through the Android Bluetooth APIs. These APIs let
applications wirelessly connect to other Bluetooth devices,
enabling point-to-point and multipoint wireless features.
Using the Bluetooth APIs, an Android application can
perform the following:
Scan for other Bluetooth devices
Query the local Bluetooth adapter for paired Bluetooth
devices
Establish RFCOMM channels
Connect to other devices through service discovery
Transfer data to and from other devices
Manage multiple connections
The Basics
This document describes how to use the Android Bluetooth
APIs to accomplish the four major tasks necessary to
communicate using Bluetooth: setting up Bluetooth, finding
devices that are either paired or available in the local area,
connecting devices, and transferring data between devices.
All of the Bluetooth APIs are available in the
android.bluetooth package. Here's a summary of the classes and
interfaces you will need to create Bluetooth connections:
BluetoothAdapter
Represents the local Bluetooth adapter (Bluetooth radio). The
BluetoothAdapter is the entry-point for all Bluetooth
interaction. Using this, you can discover other Bluetooth devices, query a list of bonded (paired) devices, instantiate
a
BluetoothDevice using a known MAC address, and create a BluetoothServerSocket to listen for
communications from other devices.
BluetoothDevice
Represents a remote Bluetooth device. Use this to request a connection with a remote device through a
BluetoothSocket or query information about the device such as its name, address, class, and bonding state.
BluetoothSocket
Represents the interface for a Bluetooth socket (similar to a TCP
Socket). This is the connection point that allows
an application to exchange data with another Bluetooth device via InputStream and OutputStream.
BluetoothServerSocket
Represents an open server socket that listens for incoming requests (similar to a TCP
ServerSocket). In order to
connect two Android devices, one device must open a server socket with this class. When a remote Bluetooth
device makes a connection request to the this device, the
BluetoothServerSocket will return a connected
Bluetooth
|
Android Developers http://developer.android.com/guide/topics/wireless/bluet...
1 of 13 2012-5-15 11:10
BluetoothSocket when the connection is accepted.
BluetoothClass
Describes the general characteristics and capabilities of a Bluetooth device. This is a read-only set of properties
that define the device's major and minor device classes and its services. However, this does not reliably describe
all Bluetooth profiles and services supported by the device, but is useful as a hint to the device type.
BluetoothProfile
An interface that represents a Bluetooth profile. A Bluetooth profile is a wireless interface specification for
Bluetooth-based communication between devices. An example is the Hands-Free profile. For more discussion of
profiles, see
Working with Profiles
BluetoothHeadset
Provides support for Bluetooth headsets to be used with mobile phones. This includes both Bluetooth Headset and
Hands-Free (v1.5) profiles.
BluetoothA2dp
Defines how high quality audio can be streamed from one device to another over a Bluetooth connection. "A2DP"
stands for Advanced Audio Distribution Profile.
BluetoothHealth
Represents a Health Device Profile proxy that controls the Bluetooth service.
BluetoothHealthCallback
An abstract class that you use to implement
BluetoothHealth callbacks. You must extend this class and implement
the callback methods to receive updates about changes in the application’s registration state and Bluetooth channel
state.
BluetoothHealthAppConfiguration
Represents an application configuration that the Bluetooth Health third-party application registers to communicate
with a remote Bluetooth health device.
BluetoothProfile.ServiceListener
An interface that notifies
BluetoothProfile IPC clients when they have been connected to or disconnected from
the service (that is, the internal service that runs a particular profile).
Bluetooth Permissions
In order to use Bluetooth features in your application, you need to declare at least one of two Bluetooth permissions:
BLUETOOTH and BLUETOOTH_ADMIN.
You must request the
BLUETOOTH permission in order to perform any Bluetooth communication, such as requesting a
connection, accepting a connection, and transferring data.
You must request the
BLUETOOTH_ADMIN permission in order to initiate device discovery or manipulate Bluetooth settings.
Most applications need this permission solely for the ability to discover local Bluetooth devices. The other abilities
granted by this permission should not be used, unless the application is a "power manager" that will modify Bluetooth
settings upon user request. Note: If you use
BLUETOOTH_ADMIN permission, then must also have the BLUETOOTH
permission.
Declare the Bluetooth permission(s) in your application manifest file. For example:
<manifest ... >
<uses-permission android:name="android.permission.BLUETOOTH" />
...
</manifest>
See the
<uses-permission> reference for more information about declaring application permissions.
Bluetooth
|
Android Developers http://developer.android.com/guide/topics/wireless/bluet...
2 of 13 2012-5-15 11:10
Figure 1: The enabling Bluetooth
dialog.
Setting Up Bluetooth
Before your application can communicate over Bluetooth, you need to verify
that Bluetooth is supported on the device, and if so, ensure that it is enabled.
If Bluetooth is not supported, then you should gracefully disable any Bluetooth
features. If Bluetooth is supported, but disabled, then you can request that the
user enable Bluetooth without leaving your application. This setup is
accomplished in two steps, using the
BluetoothAdapter.
Get the
BluetoothAdapter
The
BluetoothAdapter is required for any and all Bluetooth activity. To get
the
BluetoothAdapter, call the static getDefaultAdapter() method. This
returns a
BluetoothAdapter that represents the device's own Bluetooth
adapter (the Bluetooth radio). There's one Bluetooth adapter for the entire
system, and your application can interact with it using this object. If
getDefaultAdapter() returns null, then the device does not support Bluetooth and your story ends here. For
example:
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
}
1.
Enable Bluetooth
Next, you need to ensure that Bluetooth is enabled. Call
isEnabled() to check whether Bluetooth is currently
enable. If this method returns false, then Bluetooth is disabled. To request that Bluetooth be enabled, call
startActivityForResult() with the ACTION_REQUEST_ENABLE action Intent. This will issue a request to enable
Bluetooth through the system settings (without stopping your application). For example:
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
A dialog will appear requesting user permission to enable Bluetooth, as shown in Figure 1. If the user responds
"Yes," the system will begin to enable Bluetooth and focus will return to your application once the process
completes (or fails).
The REQUEST_ENABLE_BT constant passed to
startActivityForResult() is a locally defined integer (which must be
greater than 0), that the system passes back to you in your
onActivityResult() implementation as the
requestCode parameter.
If enabling Bluetooth succeeds, your activity receives the
RESULT_OK result code in the onActivityResult()
callback. If Bluetooth was not enabled due to an error (or the user responded "No") then the result code is
RESULT_CANCELED.
2.
Optionally, your application can also listen for the
ACTION_STATE_CHANGED broadcast Intent, which the system will
broadcast whenever the Bluetooth state has changed. This broadcast contains the extra fields
EXTRA_STATE and
EXTRA_PREVIOUS_STATE, containing the new and old Bluetooth states, respectively. Possible values for these extra fields
are
STATE_TURNING_ON, STATE_ON, STATE_TURNING_OFF, and STATE_OFF. Listening for this broadcast can be useful to
detect changes made to the Bluetooth state while your app is running.
Tip: Enabling discoverability will automatically enable Bluetooth. If you plan to consistently enable device
discoverability before performing Bluetooth activity, you can skip step 2 above. Read about
enabling
discoverability, below.
Bluetooth
|
Android Developers http://developer.android.com/guide/topics/wireless/bluet...
3 of 13 2012-5-15 11:10
剩余12页未读,继续阅读
flyzqx
- 粉丝: 1
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
- MW全能培训汽轮机调节保安系统PPT教学课件.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论30