第13章Bluetooth和Sensor.pptVIP

  • 6
  • 0
  • 约5.34千字
  • 约 17页
  • 2018-03-09 发布于河南
  • 举报
第13章Bluetooth和Sensor

第13章 Bluetooth和Sensor 13.1、Bluetooth 13.1.1、Bluetooth简介 1、Bluetooth是10米内短距通信协议 2、Bluetooth采用端到端(peer-to-peer)网络存取和数据交换 3、Bluetooth采用主从(master-slave) 控制 4、Android采用端到端的加密通信方式,设备需绑定 13.1.2、Bluetooth 的类 类 描述 BluetoothAdapter 描述Bluetooth硬件和接口构建,发现和检索绑定设备 BluetoothClass 描述Blueetooth通信的相关常数和操作 BluetoothDevice 描述一个Bluetooth远程设备 BluetoothSocket Bluetooth设备数据交换端口,主设备创建套接字 BluetoothServerSocket Bluetooth从设备监听主设备的端口 13.2、Bluetooth 实现 13.2.1、Bluetooth实现步骤 1、扫描Bluetooth设备 2、查询绑定的本地Bluetooth设备Adapter 3、建立RFCOMM通道 4、建立同其他Bluetooth设备联接 5、数据传输 6、联接管理 类 描述 BluetoothProfile Bluetooth无线通信规范接口定义 BluetoothHeadset Blueetooth耳机 BluetoothA2dp Blueetooth传输高质量音频规范 BluetoothProfile.ServiceListener 通知Bluetooth IPC客户端规范接口定义 13.2、 类 描述 SensorManager 传感器硬件的主接口,用于访问传感器 Sensor 传感器类 SensorEvent 传感器事件 SensorEventListener 接收传感器事件 传感器类型 描述 Sensor.TYPE_ACCELEROMETER 三维加速度传感器 Sensor.TYPE_GYROSCOPE 陀螺仪传感器 Sensor.TYPE_LIGHT 亮度传感器 Sensor.TYPE_MAGNETIC_FIELD 磁场传感器 Sensor.TYPE_ORIENTATION 三维方向传感器 Sensor.TYPE_PRESSURE 压力传感器 Sensor.TYPE_PROXIMITY 距离传感器 Sensor.TYPE_TEMPERATURE 温度传感器 3.5、视图类(views) 3.5.1、视图类层次结构 1、 视图类是android UI元素的构造块 2、视图类的属性可以通过方法动态设置,如setText 3、视图类属性可以设计阶段设置 3.5.2、视图类分类 1、视图布局类 2、适配器视图类 3、视图元素类 步骤: 1、创建ListActivity子类 2、创建列表项的布局 3、创建ArrayAdapter(context, TviewResid, T[])实例 4、设置列表视图setListAdapter(ListAdapter) 5、如果需要设置视图过滤setTextFilterEnabled(boolean) 3.7.3、Spinner(spinnerExample) 步骤: 1、创建Activity子类 2、设置布局setContentView() 3、获取Spinner实例(findViewById(int)) 4、创建ArrayAdapter实例(createFromResource(Context, ArrayResId, tViewResId) 5、创建下拉列表视图模式(setDropDownViewResource(int)) 6、设置下拉列表视图setAdapter(ArrayAdapter) 3.7.4、定制BaseAdapter类实现列表(baseAdapterAndList) 步骤: 1、实现BaseAdapter子类 子类构造方法初始化, 获取图片BitmapFactory.decodeResource(Resources, int) 创建布局文件实例对象 LayoutInflater.from(context) getCount()方法,列表元素数量 getItem()方法,返回列表元素 getItemId()方法,返回列表元素位置 getView()方法,返回视图元素对象 获取布局文件(layoutInflater.inflate(Resources, viewgroup) 设置每列相应元素的值 2、设置列表视图setListAdapter(ListAdapter) 3.7.5、定制CursorAdapter类实现自动查找(cursorAdapterAndAuto

文档评论(0)

1亿VIP精品文档

相关文档