react native 的蓝牙开发基本尚未人介绍,通过摸索终于有了收获html
这里介绍android平台下的蓝牙开发node
在Android平台下建立BleManagerModule,BleManagerPackage,这个只是react native基础的交互说明,具体参考: http://facebook.github.io/react-native/docs/native-modules-android.htmlreact
把接口react native和android接口调用弄通,而后把蓝牙相关代码加入,这个就不介绍了,就是在加蓝牙的时候出现的bug,下面是解决方法android
这里须要执行,在node.js下git
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --sourcemap-output android/app/src/main/assets/index.android.map --assets-dest android/app/src/main/res/
否则会报错误,具体参考 http://blog.csdn.net/b992379702b/article/details/52234479github
而后在代码中加入implements LifecycleEventListener,这个是为了增长生命周期,在结束的时候释放掉蓝牙的资源。npm
public class BleManagerModule extends ReactContextBaseJavaModule implements ActivityEventListener, LifecycleEventListener @Override public void onHostResume() { } @Override public void onHostPause() { } @Override public void onHostDestroy() { btconfig.stopBleScan(); }
好吧,最后上传个人代码,给你们留个福利。 https://git.oschina.net/zxforme/react-native-ble 后续会不断更新。react-native
记得要npm install更新,各位点个赞吧。哈哈app
好吧。。我最后找到官方的ble,,百度真垃圾,google一下就出来了。。附上地址https://github.com/innoveit/react-native-ble-manageride