Giter Club home page Giter Club logo

sweettooth-android-ble's Introduction

SweetTooth

A simplistic, sugarcoated, Android BLE Wrapper

Let's Get Down To Business

  1. Initialize SweetToothManager with Application (to get context)
  2. Add SweetToothListener to SweetToothManager
    • This listener will get notified of discovered devices
  3. Start scanning
    • You know, it starts scanning for devices
	
	// Init instance and add listener
	SweetToothManager.getInstance().initInstance(getApplication());
	SweetToothManager.getInstance().addListener(new SweetToothListener() {

		@Override
		public void onDiscoveredDevice(BluetoothDevice arg0, int arg1, byte[] arg2) {
			Log.d("SweetTooth", "We got device - " + arg0.getName());
		}

		@Override
		public void onScanningIntervalStateChange(boolean arg0) {
			
		}

		@Override
		public void onScanningStateChange(boolean arg0) {
			
		}
		
	});

	// Starts scanning - this should probably start on a button press
	SweetToothManager.getInstance().start();

Scans on interval - a little bit of hacks

Not sure if needed yet

public class MainActivity extends Activity implements SweetToothListener {

	// Starts scanning on an interval - turns on scan for 5 seconds, turns off scanning for 0.5 seconds
	// This is used (in this case) since Android as no way to turn on multiple discoveries of an advertising device
	SweetToothManager.getInstance().startOnInterval(5000, 500);
    
}

WTF is with the scanRecord?

The scan record contains advertisement data but the simple byte array does not provide easy access to the information.

BLEAdvertisementData class parses the scanRecord and provides helpers for getting all of the data out. If the helpers aren't enough, the BLEAdvertisementData class extends HashMap<String, String[] array> so you can grab any data you want out of it.

	@Override
	public void discoveredDevice(BluetoothDevice device, int rssi, byte[] scanRecord) {
		BLEAdvertisementData blueTipzData = BLEAdvertisementData.parseAdvertisementData(scanRecord);
		
		Log.d("SweetTooth", "Flags - " + blueTipzData.getFlags() );
		
		Log.d("SweetTooth", "16 bit UUIDS - " + Arrays.toString( blueTipzData.get16BitServiceUUIDs() ) );
		Log.d("SweetTooth", "More 16 bit UUIDS - " + Arrays.toString( blueTipzData.getMore16BitServiceUUIDs() ) );
		
		Log.d("SweetTooth", "32 bit UUIDS - " + Arrays.toString( blueTipzData.get32BitServiceUUIDs() ) );
		Log.d("SweetTooth", "More 32 bit UUIDS - " + Arrays.toString( blueTipzData.getMore32BitServiceUUIDs() ) );
		
		Log.d("SweetTooth", "128 bit UUIDS - " + Arrays.toString( blueTipzData.get128BitServiceUUIDs() ) );
		Log.d("SweetTooth", "More 128 bit UUIDS - " + Arrays.toString( blueTipzData.getMore128BitServiceUUIDs() ) );

		Log.d("SweetTooth", "Local name complete - " + blueTipzData.getLocalNameComplete() );
		Log.d("SweetTooth", "Local name shortened - " + blueTipzData.getLocalNameShortened() );
	}

sweettooth-android-ble's People

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.