{"id":22860060,"url":"https://github.com/reelyactive/ble-android-sdk","last_synced_at":"2025-04-30T17:47:07.405Z","repository":{"id":27553863,"uuid":"31035641","full_name":"reelyactive/ble-android-sdk","owner":"reelyactive","description":"SDK for Android devices to interact with reelyActive reelceivers via Bluetooth Smart (BLE).  We believe in an open Internet of Things.","archived":false,"fork":false,"pushed_at":"2016-03-31T14:22:24.000Z","size":519,"stargazers_count":16,"open_issues_count":0,"forks_count":8,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-24T20:22:30.882Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://reelyactive.github.io/ble-android-sdk/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reelyactive.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-19T20:38:21.000Z","updated_at":"2024-05-05T18:06:04.000Z","dependencies_parsed_at":"2022-08-07T13:00:31.502Z","dependency_job_id":null,"html_url":"https://github.com/reelyactive/ble-android-sdk","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reelyactive%2Fble-android-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reelyactive%2Fble-android-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reelyactive%2Fble-android-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reelyactive%2Fble-android-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reelyactive","download_url":"https://codeload.github.com/reelyactive/ble-android-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251754422,"owners_count":21638506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-13T09:08:49.680Z","updated_at":"2025-04-30T17:47:07.381Z","avatar_url":"https://github.com/reelyactive.png","language":"Java","funding_links":[],"categories":["Beacon Development"],"sub_categories":[],"readme":"# reelyactive-ble-android-sdk\nThis SDK allows you to scan beacons and advertise as a beacon.\n\nThe SDK is compatible with all versions of Android supporting BLE (ie. 4.3+).\n\nHave a look at the [javadoc](http://reelyactive.github.io/ble-android-sdk) !\n\n## Gradle\n\n\nAdd it to your project :\n\n```groovy\ncompile 'com.reelyactive:blesdk:0.5.0@aar'\n```\n\n## Scan with a simple API\n\n### Basics\nAdd this call in your Application class :\n\n```java\nregisterActivityLifecycleCallbacks(new ReelyAwareApplicationCallback(this) {\n    // let your IDE add what's missing\n});\n```\n\nAnd make sure any activity - which needs to get notified about bluetooth event - implements [ReelyAwareActivity](library/src/main/java/com/reelyactive/blesdk/application/ReelyAwareActivity.java) :\n```java\npublic class ReelyAwareScanActivity extends Activity implements ReelyAwareActivity {\n\n    @Override\n    public void onScanStarted() {}\n\n    @Override\n    public void onScanStopped() {}\n\n    @Override\n    public void onEnterRegion(ScanResult beacon) {}\n\n    @Override\n    public void onLeaveRegion(ScanResult beacon) {}\n}\n```\n\nThis way, Bluetooth scanning is triggered when your Activity is resumed, and stopped when it is paused.\u003cbr/\u003e\nThe [ScanResult](library/src/main/java/com/reelyactive/blesdk/support/ble/ScanResult.java) class is a clone of [Lollipop's ScanResult class](http://developer.android.com/reference/android/bluetooth/le/ScanResult.html), offering identical APIs.\n\n### Scan start\n\nThe scanning behaviour can be changed by overriding the other methods of [ReelyAwareApplicationCallback](library/src/main/java/com/reelyactive/blesdk/application/ReelyAwareApplicationCallback.java), such as \"shouldStartScan\" :\n```java\npublic class MyReelyAwareApplicationCallback extends ReelyAwareApplicationCallback {\n    @Override\n    protected boolean shouldStartScan() {\n        return isBound(); // always check this at least\n    }\n\n    @Override\n    public boolean onBleEvent(BleService.Event event, Object data) {\n        if(!super.onBleEvent(event, data)) {\n            // do your background stuff here\n        }\n        return true;\n    }\n\n}\n```\n\n### Beacon filter\nThe default filter for the scan is the following :\n```java\n    protected ScanFilter getScanFilter() {\n        return new ScanFilter.Builder().setServiceUuid(\n            ParcelUuid.fromString(\"7265656C-7941-6374-6976-652055554944\")\n        ).build();\n    }\n```\nOverride this method and you can set the filter you want !\n\n## Scan with the support API\nThis is API is similar to what you usually find in a support package : the same APIs as on the latest Android version (Lollipop here), but on a different set of classes.\n\nThis API differs from the previous one, in the sens that you have to completely handle the scan lifecycle.\n\nFirst, get a [BluetoothLeScannerCompat](library/src/main/java/com/reelyactive/blesdk/support/ble/BluetoothLeScannerCompat.java), and decide what you'll do in a [ScanCallback](library/src/main/java/com/reelyactive/blesdk/support/ble/ScanCallback.java) :\n```java\nBluetoothLeScannerCompat scanner = BluetoothLeScannerCompatProvider.getBluetoothLeScannerCompat(mContext);\nScanCallback scanCallback = new ScanCallback() {\n    @Override\n    public void onScanResult(int callbackType, ScanResult result) {\n        if (callbackType == ScanSettings.CALLBACK_TYPE_FIRST_MATCH) {\n            // FOUND A BEACON\n        } else {\n            // LOST A BECON\n        }\n    }\n\n    @Override\n    public void onScanFailed(int errorCode) {\n        // FAILED TO START SCANNING\n    }\n};\n```\n\nThen, start a scan :\n```java\nscanner.startScan(\n    // Create a filter\n    Arrays.asList(new ScanFilter.Builder().setServiceUuid(\n        ParcelUuid.fromString(\"7265656c-7941-6374-6976-652055554944\"))\n        .build()\n    ),\n    // Use specific scan settings\n    new ScanSettings.Builder() //\n            .setCallbackType(ScanSettings.CALLBACK_TYPE_FIRST_MATCH |\n                ScanSettings.CALLBACK_TYPE_MATCH_LOST) //\n            .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) //\n            .setScanResultType(ScanSettings.SCAN_RESULT_TYPE_FULL) //\n            .build(),\n    scanCallback\n);\n```\nWhen you are done, stop the scan :\n```java\nscanner.stopScan(scanCallback);\n```\n\n## Advertising\nWe desgined the advertising, so that it will be compatible with [hlc-server](https://github.com/reelyactive/).\n\nYou can get a reference to a [BleAdvertiser](library/src/main/java/com/reelyactive/blesdk/advertise/BleAdvertiser.java) with the following code:\n```java\nBleAdvertiser avertiser = BleAdvertiserProvider.getAdvertiser(context);\n\n```\n\nOnce you got it, you can advertise:\n```java\nadvertiser.startAdvertising(uuid);\n```\nThough, if you are using devices on which this feature is not available, it is advised to use:\n```java\nadvertiser.startAdvertising(uuid, closestBeacon);\n```\nThis will make sure that any device can report data to HLC.\u003cbr/\u003e\nGive it a scan result which matches the closest beacon, for example using :\n```java\nList\u003cScanResult\u003e results = myAppCallback.getBleService().getMatchingRecentResults(myAppCallback.getScanFilter());\n```\n\nIf you run your own HLC server, you might want to use:\n```java\nadvertiser.startAdvertising(uuid, closestBeacon, myHlcServerUrl);\n```\n# Other information\nThis project uses the Apache Licence, and embeds code from [Google](https://github.com/google/uribeacon/tree/master/android-uribeacon/uribeacon-library/src/main/java/org/uribeacon/scan/compat)'s UriBeacon project.\n\n# Other great projects from ReelyActive\nHave a look [there](https://github.com/reelyactive) !\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freelyactive%2Fble-android-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freelyactive%2Fble-android-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freelyactive%2Fble-android-sdk/lists"}