• Stars
    star
    1,320
  • Rank 35,625 (Top 0.8 %)
  • Language
    Java
  • Created about 8 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bluetooth Helper Library.—-蓝牙操作库

Bluetooth Helper Library

繁體中文 | 简体中文 | English

A library makes your app's bluetooth operation(for Smart Iot Hardware especially) so easy!

image

Don't forget give me a star :)

Feature

  • Packaged common bluetooth operations, such as device discovery, connect the remote device and more.
btHelperClient.searchDevices(listener);
  • Sending messages is such as Http, you send a message to the remote device(not need to connect device firstly, such as Smart Iot Hardware) then you could get a response and a status code.
btHelperClient.sendMessage("20:15:03:18:08:63", item, true, new OnSendMessageListener() {

        @Override
        public void onSuccess(int status, String response) {
        }

        ...

});

Dependency

There are two ways:

  • clone this project, and use as dependency
  • just add following code to you build.gradle:
   // Add it in your root build.gradle at the end of repositories
	allprojects {
		repositories {
			...
			maven { url "https://jitpack.io" }
		}
	}
	// Add the dependency
   dependencies {
       compile 'com.github.a-voyager:BluetoothHelper:f71d40a98b'
   }

Usage

  • Get the instance use a Context object to initialize
btHelperClient = BtHelperClient.from(MainActivity.this);
  • Send message to the remote device send message asynchronously, callback in main thread. parameters means: device's mac address, message object, if need to obtain response, SendMessageListener.
MessageItem item = new MessageItem("Hello");

btHelperClient.sendMessage("20:15:03:18:08:63", item, true, new OnSendMessageListener() {

        @Override
        public void onSuccess(int status, String response) {
           // Call when send a message succeed, and get a response from the remote device

           // status:   the status describes ok or error.
           //           1 respect the response is valid, -1 respect the response is invalid
           // response: the response from the remote device, you can call response.getBytes() to get char[]

        }

        @Override
        public void onConnectionLost(Exception e) {
            e.printStackTrace();
        }

        @Override
        public void onError(Exception e) {
            e.printStackTrace();
        }

});
  • Close connection just call close() method
    @Override
    protected void onDestroy() {
        super.onDestroy();

        btHelperClient.close();

    }

More API

  • Search devices search devices with just calling searchDevices() method
btHelperClient.searchDevices(new OnSearchDeviceListener() {

        @Override
        public void onStartDiscovery() {
            // Call before discovery devices

            Log.d(TAG, "onStartDiscovery()");

        }

        @Override
        public void onNewDeviceFound(BluetoothDevice device) {
            // Call when found a new device

            Log.d(TAG, "new device: " + device.getName() + " " + device.getAddress());

        }

        @Override
        public void onSearchCompleted(List<BluetoothDevice> bondedList, List<BluetoothDevice> newList) {
            // Call when the discovery process completed

            Log.d(TAG, "SearchCompleted: bondedList" + bondedList.toString());
            Log.d(TAG, "SearchCompleted: newList" + newList.toString());

        }

        @Override
        public void onError(Exception e) {

            e.printStackTrace();

        }

});
  • Set filter use a filter to check if a given response is an expect data.
btHelperClient.setFilter(new Filter() {

       @Override
       public boolean isCorrect(String response) {
           return response.trim().length() >= 5;
       }

});

To-Do List

  • Listening data mode
  • BtHelperServer

License

The MIT License (MIT)

Copyright (c) 2015 WuHaojie

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

More Repositories

1

AutoInstaller

应用自动静默更新安装库.
Java
1,064
star
2

ScrollNumber

custom widget--srcoll number
Java
796
star
3

WeekToDo

《番茄周》软件开源项目
Java
269
star
4

NetView

自定义控件——蜘网图(雷达图)控件
Java
34
star
5

White

“白噪声”软件开源项目.
Java
31
star
6

GraphView

自定义控件——天气温度折线图
Java
29
star
7

StringExtractor

🚀One Key to Extract String Resource
Java
18
star
8

SmartHouse_Android

单片机课程实践——智能家居系统(安卓端)
Java
9
star
9

LoginSystem_Client

登录注册系统(桌面客户端)——Java课程实践
Java
7
star
10

WaterBubble

自定义控件——水波纹特效
Java
6
star
11

Awesome-Widgets

some simple ui widgets for android developer
Java
5
star
12

ZhihuDaily

仿知乎日报应用.
Java
4
star
13

Light

安卓手电筒应用
Java
4
star
14

WiFi_Tool

安卓WiFi密码查看器
Java
3
star
15

WeatherStation

课程实践——气象站 App
Java
3
star
16

AndroidApplication

This is a repository contains some interesting libraries, app codes, demos...(包含个人收藏的库,应用源码,以及小案例...)
Java
3
star
17

LoginSystem_Server

登录注册系统(Web服务端)——Java课程实践
Java
2
star
18

ControlPCServiceDemo

手机控制局域网内的电脑——电脑端
Java
2
star
19

MqttLib

Mqtt 通信封装库.
Java
2
star
20

AndroidApp

This is a repository backup for AndroidApplication repository.
Java
2
star
21

IndoorMapDemo

use mappwidget implements indoor map
Java
2
star
22

LoginProjectClient

B/S模式登录注册注销(Android客户端)
Java
2
star
23

CountDownButton

自定义控件——验证码倒计时按钮.
Java
2
star
24

ControlPCDemo

手机控制局域网内的电脑——安卓端
Java
2
star
25

Python

my python demos
Python
1
star
26

PingTopDemo

Java
1
star
27

TrackClient

航迹分析管理项目_客户端
Java
1
star
28

MultiSwitchButton

a view implements a switch button with multi choice.
Java
1
star
29

BTChat

蓝牙聊天Demo
Java
1
star
30

a-voyager.github.io

Repository for personal website.
HTML
1
star
31

Awesome-Python

闲暇时光写的一些有趣的 Python 小玩具.
Python
1
star
32

EnvMonitorSystem

智能家居环境监测系统(java上位机软件)——Java课程实践
Java
1
star
33

StepCounter

计步器
Java
1
star
34

MySqlDemo

JAVA链接MySQL数据库Demo
Java
1
star
35

SmartHouse_Server

单片机课程实践——智能家居系统(服务器端)
Java
1
star
36

RxDemo

时下流行火热的框架使用方法案例集合.
Java
1
star
37

MenuDemo

仿天天动听滑动菜单
Java
1
star