Android 2.3 r1 API中文文档——BluetoothServerSocket(Android Club SYSU)

合集下载

[转载]蓝牙4-Android BLE开发官方文档翻译

[转载]蓝牙4-Android BLE开发官方文档翻译
作者 风雨byt (/users/fdba5151fd6e) 2016.03.02 15:07 写了24530字,被50人关注,获得了98个喜欢 (/users/fdba5151fd6e)
添加关注 (/sign_in)
[转载]蓝牙4.0——Android BLE开发官方文档翻译
字数3340 阅读1719 评论2 喜欢19
... } 如果你只想扫描指定类型的外围设备,可以改为调用startLeScan(UUID[], BluetoothAdapter.LeScanCallback)),需要提供 你的app支持的GATT services的UUID对象数组。 作为BLE扫描结果的接口,下面是BluetoothAdapter.LeScanCallback的实现。
发现BLE设备 为了发现BLE设备,使用startLeScan())方法。这个方法需要一个参数BluetoothAdapter.LeScanCallback。你必须实现它 的回调函数,那就是返回的扫描结果。因为扫描非常消耗电量,你应当遵守以下准则: 只要找到所需的设备,停止扫描。 不要在循环里扫描,并且对扫描设置时间限制。以前可用的设备可能已经移出范围,继续扫描消耗电池电量。 下面代码显示了如何开始和停止一个扫描: // 扫描和显示可以提供的蓝牙设备.
// 使用此检查确定BLE是否支持在设备上,然后你可以有选择性禁用BLE相关的功能 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show(); finish(); }

安卓蓝牙中文翻译帮助文档

安卓蓝牙中文翻译帮助文档
查询已配对设备 在执行设备发现之前,先查询下已经配对的设备,来看下我们想要的设备是不是已经是知 道的还是值得的。 Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); // If there are paired devices if (pairedDevices.size() > 0) {
尔类型,它表明发现过程启动是否成功。这个发现过程通常包含了 12S 的扫描查询过程,接 下来就是包含了每个被发现设备的的页扫描来提取蓝牙设备的名字。
// Create a BroadcastReceiver for ACTION_FOUND private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
如果你将要初始化一个连接到远程设备,你就没有必要打开可见性。使能可见性仅仅只是让 你的应用程序作为服务端 Socket,它用来接受输入连接请求。因为远程设备在初始化连接之 前必须先发现这个设备。
连接设备 为了在你的应用程序里面让 2 个设备建立连接,你必须实行服务端和客户端连接机制。因为 一个设备必须打开一个 server socket 服务端套接字而另一个设备必须初始化这个连接(使 用 server 设备的物理地址来建立连接)。当 server 和 client 他们之间在同一个 RFCOMM 通 信通道之间有一个连接好了的 BluetoothSocket 的时候,server 和 client 服务端和客户端就被 认为是已经建立好了连接。在这个点上,每个设备就可以获得输入输出流,数据传输也可以 开始。关于这点我们在管理连接那节介绍,我们这节只讲如何在 2 个设备之间初始化连接。

android蓝牙介绍二蓝牙代码架构及其uart 到rfcomm流程

android蓝牙介绍二蓝牙代码架构及其uart 到rfcomm流程

Android bluetooth介绍(二)android 蓝牙代码架构及其uart 到rfcomm 流程一、Android Bluetooth Architecture蓝牙代码架构部分(google 官方蓝牙框架)Android的蓝牙系统,自下而上包括以下一些内容如上图所示:1、串口驱动Linux的内核的蓝牙驱动程、Linux的内核的蓝牙协议的层2、BlueZ的适配器BlueZ的(蓝牙在用户空间的函式库)bluez代码结构Bluetooth协议栈BlueZ分为两部分:内核代码和用户态程序及工具集。

(1)、内核代码:由BlueZ核心协议和驱动程序组成Bluetooth协议实现在内核源代码 kernel/net/bluetooth中。

包括hci,l2cap,hid,rfcomm,sco,SDP,BNEP等协议的实现。

(2)、驱动程序:kernel/driver/bluetooth中,包含Linuxkernel对各种接口的Bluetooth device的驱动,如:USB接口,串口等。

(3)、用户态程序及工具集:包括应用程序接口和BlueZ工具集。

BlueZ提供函数库以及应用程序接口,便于程序员开发bluetooth应用程序。

BlueZ utils是主要工具集,实现对bluetooth设备的初始化和控制。

3、蓝牙相关的应用程序接口Android.buletooth包中的各个Class(蓝牙在框架层的内容-----java)同样下图也是一张比较经典的蓝牙代码架构图(google官方提供)二、蓝牙通过Hciattach启动串口流程:1、hciattach总体流程2、展讯hciattach代码实现流程:三、具体代码分析1、initrc中定义idh.code\device\sprd\sp8830ec_nwcn\init.sc8830.rc1.service hciattach /system/bin/hciattach -n /dev/sttybt0 sprd_shark2.socket bluetooth stream 660 bluetooth bluetoother bluetooth4.group wifi bluetooth net_bt_admin net_bt inet net_raw net_admin system5.disabled6.oneshotadb 下/dev/ttybt0(不同平台有所不同)PS 进程中:hicattch2、/system/bin/hciattach 执行的Main函数idh.code\external\bluetooth\bluez\tools\hciattach.cservice hciattach /system/bin/hciattach -n /dev/sttybt0sprd_shark 传进两个参数,/dev/sttybt0 和 sprd_shark1.i nt main(int argc, char *argv[])2.{3.………………4.for (n = 0; optind < argc; n++, optind++) {5.char *opt;6.7.opt = argv[optind];8.9.switch(n) {10. case 0://(1)、解析驱动的位置;11. dev[0] = 0;12. if (!strchr(opt, '/'))13. strcpy(dev, "/dev/");14. strcat(dev, opt);15. break;16.17. case 1://(2)、解析串口的配置相关参数;18. if (strchr(argv[optind], ',')) {19. int m_id, p_id;20. sscanf(argv[optind], "%x,%x",&m_id, &p_id);21. u = get_by_id(m_id, p_id);22. } else {23. u = get_by_type(opt);24. }25.26. if (!u) {27. fprintf(stderr, "Unknown device type or id\n");28. exit(1);29. }30.31. break;32.33. case 2://(3)、通过对前面参数的解析,把uart[i]中的数值初始化;34. u->speed = atoi(argv[optind]);35. break;36.37. case 3:38. if (!strcmp("flow", argv[optind]))39. u->flags |= FLOW_CTL;40. else41. u->flags &= ~FLOW_CTL;42. break;43.44. case 4:45. if (!strcmp("sleep", argv[optind]))46. u->pm = ENABLE_PM;47. else48. u->pm = DISABLE_PM;49. break;50.51. case 5:52. u->bdaddr = argv[optind];53. break;54. }55. }56.57.………………58. if (init_speed)//初始化串口速率;59. u->init_speed = init_speed;60.………………61. n = init_uart(dev, u, send_break, raw);//(4)、初始化串口;62.………………63.64. return 0;65.}(1)、解析驱动的位置;1.if (!strchr(opt, '/'))2.strcpy(dev, "/dev/");3.service hciattach /system/bin/hciattach -n /dev/sttybt0 sprd_shark4.dev = /dev/ttyb0(2)、解析串口的配置相关参数;获取参数对应的结构体;1.u = get_by_id(m_id, p_id);2.static struct uart_t * get_by_id(int m_id, int p_id)3.{4.int i;5.for (i = 0; uart[i].type; i++) {6.if (uart[i].m_id == m_id && uart[i].p_id== p_id)7.return &uart[i];8.}9.return NULL;10.}这个函数比较简单,通过循环对比,如传进了的参数sprd_shark和uart结构体中的对比,找到对应的数组。

Android中文API(70)——BluetoothDevice[蓝牙]

Android中文API(70)——BluetoothDevice[蓝牙]

Android中⽂API(70)——BluetoothDevice[蓝⽛]前⾔声明 欢迎转载,但请保留⽂章原始出处:)正⽂ ⼀、结构public static class BluetoothDevice extends Object implements Parcelableng.Objectandroid.bluetooth.BluetoothDevice ⼆、概述 代表⼀个远程蓝⽛设备。

让你创建⼀个带有各⾃设备的BluetoothDevice或者查询其皆如名称、地址、类和连接状态等信息。

对于蓝⽛硬件地址⽽⾔,这个类仅仅是⼀个瘦包装器。

这个类的对象是不可改变的。

这个类上的操作会使⽤这个⽤来创建BluetoothDevice类的BluetoothAdapter类执⾏在远程蓝⽛硬件上。

为了获得BluetoothDevice,类,使⽤BluetoothAdapter.getRemoteDevice(String)⽅法去创建⼀个表⽰已知MAC地址的设备(⽤户可以通过带有BluetoothAdapter类来完成对设备的查找)或者从⼀个通过 BluetoothAdapter.getBondedDevices()得到返回值的有联系的设备集合来得到该设备。

注意:需要权限 参见 三、常量String ACTION_ACL_CONNECTED⼴播活动:指明⼀个与远程设备建⽴的低级别(ACL)连接。

总是包含附加域ACL连接通过Android蓝⽛栈⾃动进⾏管理需要权限接收常量值: "android.bluetooth.device.action.ACL_CONNECTED"String ACTION_ACL_DISCONNECTED⼴播活动:指明⼀个来⾃于远程设备的低级别(ACL)连接的断开总是包含附加域ACL连接通过Android蓝⽛栈⾃动进⾏管理需要权限接收常量值: "android.bluetooth.device.action.ACL_DISCONNECTED"String ACTION_ACL_DISCONNECT_REQUESTED⼴播活动:指明⼀个为远程设备提出的低级别(ACL)的断开连接请求,并即将断开连接。

Android蓝牙编程技巧

Android蓝牙编程技巧

2016年第21期信息与电脑China Computer&Communication软件开发与应用Android蓝牙编程技巧冯基钊 赵航涛(无锡科技职业学院,江苏 无锡 214028)摘 要:蓝牙通讯具有功耗低、传输速率高和安全等优点,因此成了当前智能手机与传感设备通讯最主要的途径。

如何在Android中编写蓝牙通讯程序成为一个非常重要的课题。

笔者介绍了Android蓝牙编程的基本结构和主要API,首重介绍了蓝牙后台子线程、主线程的编程方法和技巧。

关键词:蓝牙通讯;Android编程;线程中图分类号:TN925 文献标识码:A 文章编号:1003-9767(2016)21-143-02蓝牙是一个短距离无线通信标准,适用于手机、计算机和其他电子设备之间的通信。

蓝牙采用分散式网络结构以及快跳频和短包技术,支持点对点及点对多点通信,工作在全球通用的2.4GHz ISM频段,无须申请许可证,采用时分双工传输方案实现全双工传输,具有传输速率高、功耗低、成本低的优点。

Android系统作为智能手机主流的操作系统,提供了大量蓝牙底层API,大大方便了手机蓝牙通讯程序的开发。

Android蓝牙通讯程序一般包括用于数据显示和操作的主线程和负责监听蓝牙设备接入、进行蓝牙设备连接、进行数据双向传输的后台子线程两部分。

由于后台子线程不能直接更新主线程的界面,因此借助Handler对象完成后台子线程与主线程间的数据传递。

1 Android提供的蓝牙APIAndroid蓝牙API主要存在于"android.bluetooth"包中,它提供了如扫描设备、连接设备以及对设备间的数据传输进行管理的类。

(1)BluetoothAdapter类。

它代表本地设备(手机、电脑等)的蓝牙适配器对象。

通过它可以对蓝牙设备进行基本开发,如开关蓝牙设备、扫描蓝牙设备、设置/获取蓝牙状态信息等。

可以通过调用该类的getDefaultAdapter()方法获得蓝牙适配器。

Silicon Labs Bluetooth SDK 2.12.3.0 用户指南说明书

Silicon Labs Bluetooth SDK 2.12.3.0 用户指南说明书

Bluetooth ® SDK 2.12.3.0 GA19Q2 Gecko SDK Suite September 13, 2019Silicon Labs is a leading vendor in Bluetooth hardware and software technologies, used in products such as sports and fitness, consumer electronics, beacons, and smart home applications. The core SDK is an advanced Bluetooth 5-compliant stack that provides all of the core functionality along with multiple API to simplify development. The core func-tionality offers both standalone mode allowing a developer to create and run their appli-cation directly on the SoC, or in NCP mode allowing for the use of an external host MCU. Extensions to the SDK include Bluetooth Mesh and Apple ® HomeKit ® for customers seek-ing the additional capabilities.These release notes cover SDK version(s): 2.12.3.0 released on September 13, 2019 2.12.2.0 released on August 16, 2019 2.12.1.0 released on July 19, 2019 2.12.0.0 released on June 7, 2019Compatibility and Use NoticesIf you are new to the Silicon Labs Bluetooth SDK, see Using This Release . Compatible Compilers:IAR Embedded Workbench for ARM (IAR-EWARM) version 8.30.1• Using w ine to build with the IarBuild.exe command line utility or IAR Embedded Workbench GUI on macOS or Linux could result inincorrect files being used due to collisions in wine’s hashing algorithm for generating short file names. • Customers on macOS or Linux are advised not to build with IAR outside of Simplicity Studio. Customers who do should carefullyverify that the correct files are being used. GCC (The GNU Compiler Collection) version 7.2.1, provided with Simplicity Studio.KEY FEATURESSupport for BG21 and MG21 modules: BGM210P, MGM210PContents Contents1New Items (3)1.1New Features (3)1.2New APIs (3)2Improvements (4)2.1Changed APIs (4)3Fixed Issues (5)4Known Issues in the Current Release (7)5Deprecated Items (8)6Removed Items (9)7Using This Release (10)7.1Installation and Use (10)7.2Support (10)8Legal (11)8.1Disclaimer (11)8.2Trademark Information (11)New Items 1 New ItemsGecko Platform release notes are now available through Simplicity Studio’s Launcher Perspective, under SDK Documentation > Blue-tooth SDK 2.12.n.n > Release Notes. The Gecko Platform code provides functionality that supports protocol plugins and APIs in the form of drivers and other lower layer features that interact directly with Silicon Labs chips and modules. Gecko Platform components include EMLIB, EMDRV, RAIL Library, NVM3, and mbedTLS.1.1 New FeaturesAdded in release 2.12.2.0PHY settings on a Bluetooth connectionThis feature allows the application to set preferred PHYs the stack should take into account in PHY selection, and the PHYs the stack can accept when the remote device initiates a PHY update.Added in release 2.12.0.0Advertising packet chainingWith this feature, the total amount of advertising data in an advertising packet can be up to 1650 bytes in extended advertising.1.2 New APIsFor additional documentation and command descriptions please refer to the Bluetooth Software API Reference Manual.Added in release 2.12.2.0cmd_le_gap_set_conn_phycmd_le_connection_set_preferred_phyAdded in release 2.12.0.0cmd_gatt_server_set_max_mtucmd_le_connection_set_timing_parameterscmd_le_gap_set_conn_timing_parameterscmd_le_gap_set_long_advertising_datacmd_sm_set_minimum_key_sizecmd_system_data_buffer_writecmd_system_data_buffer_clearImprovements 2 Improvements2.1 Changed APIsChanged in release 2.12.0.0cmd_le_gap_bt5_set_adv_dataRemoved the 191 bytes advertising data limitation for extended advertising.cmd_le_gap_set_adv_dataRemoved the 191 bytes advertising data limitation for extended advertising.evt_le_gap_extended_scan_responseAdded new value in packet_type parameter for data incomplete status.evt_le_gap_scan_responseAdded new value in packet_type parameter for data incomplete status.evt_sync_dataAdded new value in data_status parameter for data incomplete status.3 Fixed IssuesFixed in release 2.12.3.0404249 Fix an issue that radio may get stuck in RX state with low RSSI signals, which causes the Bluetooth stack becoming unre-sponsive.415812 Fix an IOP problem with some smartphones that connection requests from these phones are often not received, which causes connections taking too long to establish.430101 Fix an issue that setting TX Power between -13 and 0 dBm results in much lower transmit power. This issue can cause a noticeable performance degradation in RF polluted environments.430225 Fix PS Key CTUNE control for EFR32xG21 parts.431563 Fix poor OTA performance.431657 Fix a memory leak when the stack opened a connection but connection failed to establish after 6 connection intervals. Fixed in release 2.12.2.0376747 Fix the voice_over_ble Thunderboard example to dynamically perform GATT service discovery for using correct handles to read characteristic values.402234 More fixes for the disconnection issue caused by connection updates with certain parameters.420208 Fix NCP wake-up pin polarity handling (NCP_WAKEUP_POLARITY), so that the defined polarity is taken into account. 420807 Fix the usage of HFXO calibration values for xGM210 modules to avoid reading incorrect calibration values at initialization time.Fixed in release 2.12.1.0384097Fix unstable connection issue while the master device has multiple simultaneous connections and is performing scanning. 384144 Fix an issue that the stack may return the link layer procedure response timeout error when closing a Bluetooth connec-tion.391346 After advertising is started the stack will send the first advertisement straight away. Previously it might send it after the first advertisement interval has elapsed.402234 Fix disconnection issue when performing connection update with slave latency and specific interval parameters.403819 Apploader can now write images right up to the NVM start address.406537 Fix missing ADI field in chained advertisement packets.406691 The stack can now handle 255 bytes data in cmd_system_data_buffer_write command.406977 Periodic advertising data can now be set in stack when the periodic advertising has not been started. Previously this command returns an error.407673 The stack now blocks the example LTK in Bluetooth specification if sent by the other device. This security improvement addresses vulnerability CVE-2019-2102.407871 Fix default RF antenna pin selection for EFR32xG21 parts, radio boards and xGM210 modules.411446 If advertising single event at a time, the stack does not check anymore if packet length would exceed advertising interval.Previously packet_too_long error would have been returned.412625 The stack ensures that the GATT database hash value is calculated when it is first read by command gecko_cmd_gatt_server_read_attribute_value. Previously an incorrect value might be returned in this case. Additionallythe fix also prevents from overwriting the hash value with gecko_cmd_gatt_server_write_attribute_value.412725 A change was introduced in version 2.12.0 which caused compatibility issues with TB Sense mobile app. This change was reversed to fix those issues and it will be reintroduced when board detection gets improved on the TB Sense mobile appside.Fixed in release 2.12.0.0397063 In Bluetooth SDK 2.11.4 and 2.11.5, occasionally the stack is unable to receive all GATT write without response or charac-teristic value notification PDUs.337089 Deleting the bonding of a device while the device is still connected causes the stack using outdated bonding data on the connection. This has been fixed so that the connection is also closed after the bonding has been deleted.384093 The application cannot configure the maximum ATT MTU if GATT client is excluded. This has been fixed by adding a new equivalent API in GATT server class.387745 When Bluetooth runs in RTOS, the stack initialization may cause assertions.391345 Advertising could not be restarted if a timeout has been set previously.396352 Increasing security on a connection with previously bonded devices may fail.398948 The stack does not correctly inform the application about ATT MTU size change if the remote device first denies the stack’s ATT MTU exchange request and then initiates another ATT MTU exchange request.Known Issues in the Current Release 4 Known Issues in the Current ReleaseIssues in bold were added since the previous release.243009 With certain events, GCC breakpoints cannot be set. Change optimization level to none in projectsettings335894 Command gecko_cmd_gatt_discover_primary_services_by_uuidreturns success in case of incomplete parameters.None361592 The sync_data event does not report TX power. None415583 The stack returns wrong state instead of out of memory error if application sends a characteristic notification to allconnections in low memory situation. In application, treat this condition as low memory.420866 With iPhone6, the stack could become unresponsive if it is sending lots of data using characteristic notifications to the phone. In application, do not use a loop waiting for the success of sending characteristic notification operation. When an out of memory error is received from this operation, a timer should be used to retry the operation later.429536 The stack limits the maximum data payload to 191 bytes inextended connectable advertising. However this specific caseis not documented in the API reference manual.None431452 When the requested TX Power is above 0 dBm, the actualtransmit power may deviate randomly.NoneDeprecated Items 5 Deprecated ItemsDeprecated in release 2.12.2.0Deprecated APIscmd_le_connection_set_phyThe replacement is cmd_le_connection_set_preferred_phy.Deprecated in release 2.12.1.0Deprecated item: EFR32BG14 Part SupportReason: The EFR32BG14 is EOL.End-of-Service (EoS) Date: June 2020. As of this EoS date, EFR32BG14 part support will no longer be available in the then current and future GSDK releases, and EFR32BG14 parts will no longer be supported in any GSDK releases.Maintenance Period: From now until the EoS date, only critical bug fixes and security patches may be made available on currently supported GSDK releases.Replacement: EFR32BG13.Deprecated in release 2.12.0.0As of June 2019 Simplicity Studio 3.0 is being deprecated. All access will be removed from Silicon Labs' website at the end of 2019. Deprecated APIscmd_le_gap_set_conn_parametersThe replacement is cmd_le_gap_set_conn_timing_parameters.cmd_le_connection_set_parametersThe replacement is cmd_le_connection_set_timing_parameters.Removed Items 6 Removed ItemsNoneUsing This Release 7 Using This ReleaseThis release contains the following•Silicon Labs Bluetooth stack library•Bluetooth sample applicationsFor more information about the Bluetooth SDK see QSG139: Getting Started with Bluetooth® Software Development. If you are new to Bluetooth see UG103.14: Bluetooth LE Fundamentals.7.1 Installation and UseA registered account at Silicon Labs is required in order to download the Silicon Labs Bluetooth SDK. You can register at https:///apex/SL_CommunitiesSelfReg?form=short.Stack installation instruction are covered in QSG139: Getting Started with Bluetooth® Software Development.Use the Bluetooth SDK with the Silicon Labs Simplicity Studio V4 development platform. Simplicity Studio ensures that most software and tool compatibilities are managed correctly. Install software and board firmware updates promptly when you are notified. Documentation specific to the SDK version is installed with the SDK. Additional information can often be found in the knowledge base articles (KBAs). API references and other information about this and earlier releases is available on https:///.7.2 SupportDevelopment Kit customers are eligible for training and technical support. You can use the Silicon Labs Bluetooth LE web page to obtain information about all Silicon Labs Bluetooth products and services, and to sign up for product support.You can contact Silicon Laboratories support at /support.Legal8 Legal8.1 DisclaimerSilicon Labs intends to provide customers with the latest, accurate, and in-depth documentation of all peripherals and modules available for system and software implementers using or intending to use the Silicon Labs products. Characterization data, available modules and peripherals, memory sizes and memory addresses refer to each specific device, and "Typical" parameters provided can and do vary in different applications.Application examples described herein are for illustrative purposes only.Silicon Labs reserves the right to make changes without further notice and limitation to product information, specifications, and descrip-tions herein, and does not give warranties as to the accuracy or completeness of the included information. Silicon Labs shall have no liability for the consequences of use of the information supplied herein. This document does not imply or express copyright licenses granted hereunder to design or fabricate any integrated circuits. The products are not designed or authorized to be used within any Life Support System. A "Life Support System" is any product or system intended to support or sustain life and/or health, which, if it fails, can be reasonably expected to result in significant personal injury or death. Silicon Labs products are not designed or authorized for military applications. Silicon Labs products shall under no circumstances be used in weapons of mass destruction including (but not limited to) nuclear, biological or chemical weapons, or missiles capable of delivering such weapons.8.2 Trademark InformationSilicon Laboratories Inc.® , Silicon Laboratories®, Silicon Labs®, SiLabs® and the Silicon Labs logo®, Bluegiga®, Bluegiga Logo®, Clockbuilder®, CMEMS®, DSPLL®, EFM®, EFM32®, EFR, Ember®, Energy Micro, Energy Micro logo and combinations thereof, "the world’s most energy friendly microcontrollers", Ember®, EZLink®, EZRadio®, EZRadioPRO®, Gecko®, ISOmodem®, Micrium, Preci-sion32®, ProSLIC®, Simplicity Studio®, SiPHY®, Telegesis, the Telegesis Logo®, USBXpress®, Zentri, Z-Wave and others are trade-marks or registered trademarks of Silicon Labs.ARM, CORTEX, Cortex-M3 and THUMB are trademarks or registered trademarks of ARM Holdings.Keil is a registered trademark of ARM Limited.Apple and HomeKit are registered trademarks of Apple Inc. All other products or brand names mentioned herein are trademarks of their respective holders.。

Android之Bluetooth(蓝牙)编程实现

Android之Bluetooth(蓝牙)编程实现
// 布局控件 private TextView mTitle; private EditText mInputEditText; private EditText mOutEditText; private EditText mOutEditText2; private Button mSendButton; private CheckBox HEXCheckBox; private Button breakButton; private CheckBox checkBox_sixteen; /*private ImageView ImageLogoView;*/
//HEXCheckBox = (CheckBox) findViewById(R.id.radioMale); /*****************************************************************/ /*****************************************************************/ /*****************************************************************/ breakButton = (Button) findViewById(R.id.button_break); // 得到当地的蓝牙适配器 mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); /*****************************************************************/ /*****************************************************************/ /*****************************************************************/ // 初始化 CheckBox //checkBox_sixteen = (CheckBox) findViewById(R.id.checkBox_sixteen); /*****************************************************************/ /*****************************************************************/ /*****************************************************************/

Android 3.1 r1 API中文文档(6)——ImageView

Android 3.1 r1 API中文文档(6)——ImageView

Android 3.1 r1 API中文文档(6)——ImageView前言本章内容是android.widget.ImageView,为早前发布版本的完整版,版本为Android 3.1 r1,翻译来自"cnmahj"和"农民伯伯",欢迎大家访问"cnmahj"的博客:,再次感谢"/cnmahj"!欢迎你一起参与Android的中文翻译,联系我over140@。

声明欢迎转载,但请保留文章原始出处:)博客园:/Android中文翻译组:http://goo.gl/6vJQlImageView译者署名:cnmahj、农民伯伯译者博客:/cnmahj版本:Android 3.1 r1结构继承关系public class View.OnClickListner extends Viewng.Objectandroid.view.Viewandroid.widget.ImageView直接子类ImageButton, QuickContactBadge间接子类ZoomButton类概述显示任意图像,例如图标。

ImageView类可以加载各种来源的图片(如资源或图片库),需要计算图像的尺寸,比便它可以在其他布局中使用,并提供例如缩放和着色(渲染)各种显示选项。

嵌套类enum ImageView.ScaleType将图片边界缩放,以适应视图边界时的可选项XML属性公共方法public final void clearColorFilter ()(译者注:清除颜色过滤,参见这里)public int getBaseline ()返回部件顶端到文本基线的偏移量。

如果小部件不支持基线对齐,该方法返回-1。

返回值小部件顶端到文本基线的偏移量;或者是-1 当小部件不支持基线对齐时。

public boolean getBaselineAlignBottom ()返回当前视图基线是否将考虑视图的底部。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

BluetoothServerSocket
译者署名:Android Club SYSU
译者链接:
版本:Android 2.3 r1
结构
继承关系
public final class BluetoothServerSocket extends Object implements Closeable
ng.Object
android.bluetooth.BluetoothServerSocket
类概述
一个蓝牙监听端口。

蓝牙端口监听接口和TCP端口类似:Socket和ServerSocket类。

在服务器端,使用BluetoothServerSocket类来创建一个监听服务端口。

当一个连接被BluetoothServerSocket所接受,它会返回一个新的BluetoothSocket来管理该连接。

在客户端,使用一个单独的BluetoothSocket类去初始化一个外接连接和管理该连接。

最通常使用的蓝牙端口是RFCOMM,它是被Android API支持的类型。

RFCOMM是一个面向连接,通过蓝牙模块进行的数据流传输方式,它也被称为串行端口规范(Serial Port Profile,SPP)。

为了创建一个对准备好的新来的连接去进行监听BluetoothServerSocket类,使用BluetoothAdapter.listenUsingRfcommWithServiceRecord()方法。

然后调用accept()方法去监听该链接的请求。

在连接建立之前,该调用会被阻断,也就是说,它将返回一个BluetoothSocket 类去管理该连接。

每次获得该类之后,如果不再需要接受连接,最好调用在BluetoothServerSocket类下的close()方法。

关闭BluetoothServerSocket类不会关闭这个已经返回的BluetoothSocket类。

BluetoothSocket类线程安全。

特别的,close()方法总会马上放弃外界操作并关闭服务器端口。

注意:需要BLUETOOTH权限。

参见
BluetoothSocket
公共方法
Block until a connection is established, with timeout.
阻塞直到一个带超时的连接已经建立。

在一个成功建立的连接上返回一个已连接的BluetoothSocket类。

每当该调用返回的时候,它可以在此调用去接收以后新来的连接。

close()方法可以用来放弃从另一线程来的调用。

参数
timeout (译者注:阻塞超时时间)
返回值
已连接的BluetoothSocket
异常
IOException 出现错误,比如该调用被放弃,或者超时。

Block until a connection is established.
阻塞直到一个连接已经建立。

(译者注:默认超时时间设置为-1,见源码)在一个成功建立的连接上返回一个已连接的BluetoothSocket类。

每当该调用返回的时候,它可以在此调用去接收以后新来的连接。

close()方法可以用来放弃从另一线程来的调用。

返回值
已连接的BluetoothSocket
异常
IOException 出现错误,比如该调用被放弃,或者超时。

public void close ()
马上关闭端口,并释放所有相关的资源。

在其他线程的该端口中引起阻塞,从而使系统马上抛出一个IO异常。

关闭BluetoothServerSocket不会关闭接受自accept()的任意BluetoothSocket。

异常
IOException。

相关文档
最新文档