{"id":27066942,"url":"https://github.com/ubikgs/androidsensorspersistence","last_synced_at":"2026-05-08T19:32:04.508Z","repository":{"id":57729254,"uuid":"104121893","full_name":"ubikgs/AndroidSensorsPersistence","owner":"ubikgs","description":"An AndroidSensors companion library that allows to easily store AndroidSensors records","archived":false,"fork":false,"pushed_at":"2017-11-10T00:02:55.000Z","size":366,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-07-03T00:15:06.309Z","etag":null,"topics":["android","persistence","room-persistence-library","rxandroid","rxjava","sensors","sqlite"],"latest_commit_sha":null,"homepage":"","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/ubikgs.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":"2017-09-19T19:56:18.000Z","updated_at":"2017-11-17T08:53:23.000Z","dependencies_parsed_at":"2022-09-10T23:40:54.386Z","dependency_job_id":null,"html_url":"https://github.com/ubikgs/AndroidSensorsPersistence","commit_stats":null,"previous_names":[],"tags_count":5,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ubikgs%2FAndroidSensorsPersistence","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ubikgs%2FAndroidSensorsPersistence/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ubikgs%2FAndroidSensorsPersistence/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ubikgs%2FAndroidSensorsPersistence/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ubikgs","download_url":"https://codeload.github.com/ubikgs/AndroidSensorsPersistence/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247390478,"owners_count":20931429,"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":["android","persistence","room-persistence-library","rxandroid","rxjava","sensors","sqlite"],"created_at":"2025-04-05T19:29:22.098Z","updated_at":"2025-10-08T04:06:51.259Z","avatar_url":"https://github.com/ubikgs.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AndroidSensorsPersistence [![Build Status](https://travis-ci.org/ubikgs/AndroidSensorsPersistence.svg?branch=master)](https://travis-ci.org/ubikgs/AndroidSensorsPersistence) [ ![Download](https://api.bintray.com/packages/ubikgs/AndroidSensors/android-sensors-persistence/images/download.svg) ](https://bintray.com/ubikgs/AndroidSensors/android-sensors-persistence/_latestVersion) [![Javadocs](https://www.javadoc.io/badge/com.ubikgs/android-sensors-persistence.svg)](https://www.javadoc.io/doc/com.ubikgs/android-sensors-persistence)\n\n\nAn [AndroidSensors](https://github.com/ubikgs/AndroidSensors) companion library.\n\nFacilitates storing and recovering sensor and location records to and from the local SQLite database.\n\nUses [RxJava](https://github.com/ReactiveX/RxJava) to achieve an asynchronous IO and [Room Persistence Library](https://developer.android.com/topic/libraries/architecture/room.html) as an ORM.\n\n## Usage\n\nAdd the dependency\n\n```groovy\ndependencies {\n    implementation 'com.ubikgs:android-sensors:1.0.0-alpha7'\n    implementation 'com.ubikgs:android-sensors-persistence:1.0.0-alpha7'\n\n    // To conveniently work with AndroidSensors output Flowables\n    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'\n    implementation 'io.reactivex.rxjava2:rxjava:2.1.6'\n}\n```\n\nTo start using the library, you must initialize it first:\n\n```java\nContext applicationContext;\n\nAndroidSensorsPersistence androidSensorsPersistence = AndroidSensorsPersistence\n                         .builder()\n                         .build(applicationContext);\n```\nLibrary should be initialized only once. To avoid database issues, keep the instance as a singleton.\n\nThe library uses by default \"android-sensors-database\" as database name. If for any reason this database name enters in conflict with another database and you can't change it, you can configure AndroidSensorsPersistence database name doing the following:\n\n```java\nContext applicationContext;\n\nAndroidSensorsPersistence androidSensorsPersistence = AndroidSensorsPersistence\n                         .builder()\n                         .customSensorsDBName(\"new-sensors-db-name\")\n                         .build(applicationContext);\n```\n\nThen you can request some sensor record repositories in different ways:\n\n```java\nAccelerometerRepository accelerometerRepository =\n                androidSensorsPersistence.recordRepository(AccelerometerRepository.class);\n\nRecordRepository recordRepository =\n                androidSensorsPersistence.recordRepositoryBy(SensorType.ACCELEROMETER);\n\nSet\u003cRecordRepository\u003e recordRepositories =\n                androidSensorsPersistence.allRecordRepositories()\n```\n\nTo consume and store the records from a sensor:\n\n```java\nDisposable subscriber = sensorGatherer.recordStream() // From AndroidSensors library, check the README to know how to initialize this\n                .subscribeOn(Schedulers.newThread()) // Gather records on a new thread\n                .observeOn(Schedulers.io()) // Store them on the io thread\n                .buffer(1000) // Buffer 1000 elements\n                .map(new Function\u003cList\u003cSensorRecord\u003e, Single\u003cList\u003e\u003e() { // Bulk write 1000 elements\n                    @Override\n                    public Single apply(List\u003cSensorRecord\u003e sensorRecords) throws Exception {\n                        return recordRepository.createAll(sensorRecords;\n                    }\n                })\n                .subscribe(); // Keep the stream alive\n\nsubscriber.dispose() // Stop gathering and storing records\n```\n\nIf you re using Java 8 as a compilation and source target you can also do the following which is more succinct:\n\n```java\nDisposable subscriber = sensorGatherer.recordStream() // From AndroidSensors library, check the README to know how to initialize this\n                .subscribeOn(Schedulers.newThread()) // Gather records on a new thread\n                .observeOn(Schedulers.io()) // Store them on the io thread\n                .buffer(1000) // Buffer 1000 elements\n                .map(recordRepository::createAll) // Bulk write 1000 elements\n                .subscribe(); // Keep the stream alive\n\nsubscriber.dispose() // Stop gathering and storing records\n```\n\nIf you prefer to work in this way you'll need [Retrolambda](https://github.com/orfjackal/retrolambda) or [Android Studio 3.0.0 Preview](https://developer.android.com/studio/preview/index.html).\n\nWhen using Android Studio 3.0.0, you'll have to specify the following in your app `build.gradle`:\n\n```groovy\nandroid {\n\n    compileOptions {\n            sourceCompatibility JavaVersion.VERSION_1_8\n            targetCompatibility JavaVersion.VERSION_1_8\n    }\n\n}\n```\n\n## License\n    Copyright 2017 Ubik Geospatial Solutions\n    Copyright 2017 Alberto González Pérez\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fubikgs%2Fandroidsensorspersistence","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fubikgs%2Fandroidsensorspersistence","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fubikgs%2Fandroidsensorspersistence/lists"}