- 服务 Service OK
- 广播 Broadcast OK
1. 一些Bug 记录
(1)记得在Manifest中添加 服务,否则 编译不报错,服务却没有执行
<service android:name=".BLEService"/>
(2)
myViewHolder = new MyViewHolder();
Log.d(TAG, "getView: 完成了new MyViewHolder"); //一定要指定是 converView下的findViewById方法,不然如果直接写findViewId就是调用父类Activity中的此方法,会出错!
myViewHolder.tv_deviceAddress = (TextView) convertView.findViewById(R.id.tv_device_address);
myViewHolder.tv_deviceName = (TextView) convertView.findViewById(R.id.tv_device_name);
convertView.setTag(myViewHolder); //记住这个视图
Log.d(TAG, "getView: 完成了setTag(myViewHolder)");
2.广播的用法 Broadcast
(1) Intent
(2)IntentFilter
(3)注册广播 (指定广播接收器(ReceiverUtil),Intent过滤器IntentFiler) 这样就不用在Manifest中定义了
(4)发送广播 sendBroadcast
(5)去广播接收器(ReceiverUtil类中指定接收的ACTION,定义接收后的操作)
3.服务的用法 Service
4.定义ACTION_ 全局常量要用 全名!!!
//定义ACTION_ 全局常量要用 全名!!! public final static String ACTION_GATT_CONNECTED = "com.example.bluetooth.le.ACTION_GATT_CONNECTED"; public final static String ACTION_GATT_DISCONNECTED = "com.example.bluetooth.le.ACTION_GATT_DISCONNECTED"; public final static String ACTION_GATT_SERVICES_DISCOVERED = "com.example.bluetooth.le.ACTION_GATT_SERVICES_DISCOVERED"; public final static String ACTION_DATA_AVAILABLE = "com.example.bluetooth.le.ACTION_DATA_AVAILABLE"; public final static String EXTRA_DATA = "com.example.bluetooth.le.EXTRA_DATA";