Giter Club home page Giter Club logo

android-scanner-compat-library's Introduction

Android BLE Scanner Compat library

Download

The Scanner Compat library solves the problem with scanning for Bluetooth Smart devices on Android. The scanner API has changed in the Android 5.0 and has been extended in 6.0 and 8.0. Using this library you may have almost all new features even on older phones. If a feature (for example offloaded filtering or batching) is not supported natively, it will be emulated by the compat library. You may also disable the native support for filtering, batching and reporting first match or match lost if required. Advertising Extension (ScanSetting#setLegacy(boolean) or setPhy(int)) is available only on Android Oreo or newer and such calls will be ignored on older platforms, that means only legacy advertising packets on PHY LE 1M will be reported, due to the Bluetooth chipset capabilities.

Usage

The compat library may be found on jcenter repository. Add it to your project by adding the following dependency:

compile 'no.nordicsemi.android.support.v18:scanner:1.1.0'

API

The Scanner Compat API is very similar to the original one, known from Android Oreo.

Instead of getting it from the BluetoothAdapter, acquire the scanner instance using:

BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();

You also need to change the packets for ScanSettings, ScanFilter and ScanCallback classes to:

no.nordicsemi.android.support.v18.scanner

Sample

To start scanning use (example):

	BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
	ScanSettings settings = new ScanSettings.Builder()
				.setLegacy(false)
				.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).setReportDelay(1000)
				.setUseHardwareBatchingIfSupported(false).build();
	List<ScanFilter> filters = new ArrayList<>();
	filters.add(new ScanFilter.Builder().setServiceUuid(mUuid).build());
	scanner.startScan(filters, settings, scanCallback);

to stop scanning use:

	BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
	scanner.stopScan(scanCallback);

License

The Scanner Compat library is available under BSD 3-Clause license. See the LICENSE file for more info.

android-scanner-compat-library's People

Contributors

hearsilent avatar philips77 avatar sureshjoshi avatar unverbraucht 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.