怎么介绍呢,一直考虑,还是从业务流程开始,1、Meshservice初始化--》2、扫描设备---》3、连接设备--》4、扫描设备--》5、设备组网
这样分析多初学者,或者刚接触CSRdemo的比较容易!
1、从MainActivity开始,第一步是在onCreate里面初始化蓝牙mesh的入口
AndroidManifest配置文件中有一下代码,不然启动MeshService失败。
<service android:name="com.csr.csrmesh2.MeshService" android:enabled="true" android:exported="false" > </service>
MeshLibraryManager.initInstance(getApplicationContext(), MeshLibraryManager.MeshChannel.BLUETOOTH,LogLevel.DEBUG);
2、在MeshLibraryManager中进行创建service连接
private MeshLibraryManager(Context context, MeshChannel channel,LogLevel lgLevel) { Log.e(TAG,"2==init===MeshLibraryManager()"); // Log message has a tag and a priority associated with it. logLevel= lgLevel; App.bus.register(this); mContext = new WeakReference<Context>(context); mCurrentChannel = channel; Intent bindIntent = new Intent(mContext.get(), MeshService.class); context.bindService(bindIntent, mServiceConnection, Context.BIND_AUTO_CREATE); }
3、启动蓝牙,扫描蓝牙设备进行连接,重点是setBluetoothBeareEnabled接口
//激活蓝牙 private void enableBluetooth() { Log.e(TAG,"4==enable===enableBluetooth()"); mCurrentChannel = MeshChannel.