码迷,mamicode.com
首页 > 其他好文 > 详细

蓝牙通讯神器

时间:2015-06-12 15:02:30      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

下载地址:http://download.csdn.net/detail/yoyo_newbie/8799549


实例代码:

		//初始化SamBluetoothManager,可在application初始化
		SamBluetoothManager.getInstance().init(this);
		
		//设置连接,记住配置UUID
		SamBluetoothManager.getInstance().connectBluetoothDevice(address, UUID, this);
		
		//设置心跳为2秒,不设置默认为3秒
		SamBluetoothManager.getInstance().setHeartBeat(2*1000);
		
		
		//监听心跳信息
		SamBluetoothManager.getInstance().setHeartbeatListener(new SamBluetoothManager.HeartbeatListener() {
			
			@Override
			public void outline() {
				nameView.setText(address+"正在重练。。。");
				stateView.setText(address+"离线");
				//重练
				SamBluetoothManager.getInstance().reConnect(BluetoothActivity.this);
			}
			
			
			@Override
			public void online() {
				//在线中...
				nameView.setText(address+"连接成功!");
				stateView.setText(address+"在线");
			}
		});
		
		
//		//发送一条信息
//		SamBluetoothManager.getInstance().sendMessage("ddd", new SamBluetoothManager.SendMessageCallback() {
//			
//			@Override
//			public void onFinished(boolean isSuccessfull) {
//				//isSuccessfull 是否发送成功
//			}
//		});
		
		//设置监听信息
		SamBluetoothManager.getInstance().setOnRecieveListener(new SamBluetoothManager.OnRecieveListener() {
			
			@Override
			public void getData(byte[] data, int len) {
				String result =new String(data,0,  len);
				stateView.setText("收到一条信息:"+result);
			}
		});



蓝牙通讯神器

标签:

原文地址:http://blog.csdn.net/yoyo_newbie/article/details/46470379

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!