{"id":15693793,"url":"https://github.com/bradmartin/nativescript-android-sensors","last_synced_at":"2025-05-08T05:54:44.645Z","repository":{"id":34619536,"uuid":"180871072","full_name":"bradmartin/nativescript-android-sensors","owner":"bradmartin","description":"NativeScript plugin for using Android device sensors on background thread.","archived":false,"fork":false,"pushed_at":"2022-03-27T20:55:53.000Z","size":2061,"stargazers_count":7,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-08T05:54:39.310Z","etag":null,"topics":["accelerometer","android","data","nativescript","sensor"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/bradmartin.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":"2019-04-11T20:17:21.000Z","updated_at":"2024-05-30T16:23:20.000Z","dependencies_parsed_at":"2022-08-08T01:15:56.828Z","dependency_job_id":null,"html_url":"https://github.com/bradmartin/nativescript-android-sensors","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradmartin%2Fnativescript-android-sensors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradmartin%2Fnativescript-android-sensors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradmartin%2Fnativescript-android-sensors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradmartin%2Fnativescript-android-sensors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bradmartin","download_url":"https://codeload.github.com/bradmartin/nativescript-android-sensors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253009851,"owners_count":21839713,"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":["accelerometer","android","data","nativescript","sensor"],"created_at":"2024-10-03T18:49:00.545Z","updated_at":"2025-05-08T05:54:44.625Z","avatar_url":"https://github.com/bradmartin.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca align=\"center\" href=\"https://www.npmjs.com/package/nativescript-android-sensors\"\u003e\n    \u003ch3 align=\"center\"\u003eNativeScript-Android-Sensors\u003c/h3\u003e\n\u003c/a\u003e\n\u003ch4 align=\"center\"\u003eNativeScript plugin for using android device sensors that run on a background thread.\u003c/h4\u003e\n\n\u003cp align=\"center\"\u003e\n \u003ca href=\"https://www.npmjs.com/package/nativescript-android-sensors\"\u003e\n        \u003cimg src=\"https://img.shields.io/npm/v/nativescript-android-sensors.svg\" alt=\"npm\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n## Installation\n\nNativeScript 7+:\n\n```\nns plugin add nativescript-android-sensors\n```\n\nNativeScript version lower than 7:\n\n```bash\ntns plugin add nativescript-android-sensors@1.5.0\n```\n\nAndroid Sensors: https://developer.android.com/reference/android/hardware/Sensor.html\n\n## Usage\n\n```typescript\nimport { AndroidSensors, AndroidSensorListener, SensorDelay } from 'nativescript-android-sensors';\n\nconst sensors = new AndroidSensors();\nconst accelerometerSensor: android.hardware.Sensor;\nconst gyroScope: android.hardware.Sensor;\n\nconst sensorListener = new AndroidSensorListener({\n    onAccuracyChanged: (\n        sensor: android.hardware.Sensor,\n        accuracy: number\n      ) =\u003e {\n        console.log('accuracy', accuracy);\n    },\n    onSensorChanged: (result: string) =\u003e {\n        // result is being returned as a string currently\n        const parsedData = JSON.parse(result);\n        const rawSensorData = parsedData.data;\n        const sensor = parsedData.sensor;\n        const time = parsedData.time;\n    }\n});\n\nthis.sensors.setListener(sensorListener);\n\n\nsomeFunction() {\n    accelerometerSensor = sensors.startSensor(android.hardware.Sensor.TYPE_LINEAR_ACCELERATION, SensorDelay.FASTEST);\n\n    // here we are using the android const 4 which is for the TYPE_GYROSCOPE sensor\n    // https://developer.android.com/reference/android/hardware/Sensor.html#TYPE_GYROSCOPE\n    // we are passing the third argument to `startSensor` which is for maxReportLatency, if the sensor is able to support FIFO this will register the sensor with the reporting latency value, if not, the sensor registers on the background thread as normal\n    const gyroScope =  sensors.startSensor(4, SensorDelay.NORMAL, 4000000);\n\n    // maybe you wanna use a timeout and stop it after 8 seconds\n    setTimeout(() =\u003e {\n        sensors.stopSensor(gyroScope);\n    }, 8000)\n}\n\nfunctionToStopTheSensorData() {\n    sensors.stopSensor(accelerometerSensor);\n}\n```\n\n## API\n\n#### Constructor\n\nAndroidSensors (liteData: boolean = false)\n\nThe boolean argument for `liteData` changes the JSON returned from the sensor event changes. This is helpful when you are storing large amounts of dataset by reducing the redundant data from the sensor changed event.\n\n```typescript\nimport {\n  AndroidSensors,\n  AndroidSensorListener,\n  SensorDelay,\n} from 'nativescript-android-sensors';\n\nconst sensors = new AndroidSensors(true);\n```\n\n#### Methods\n\n- `setListener(listener: AndroidSensorListener): void`\n  - Set the event listener which returns data when the sensors change.\n- `startSensor(sensor: android.hardware.Sensor, delay: SensorDelay, maxReportingDelay?: number): android.hardware.Sensor`\n  - Registers the sensor with the provided reporting delay. Returns the instance of the sensor so it can be passed to the `stopSensor(sensor)` method to unregister when finished with it. The third argument to `startSensor` is for maxReportLatency, if the sensor is able to support FIFO this will register the sensor with the reporting latency value, if not, the sensor registers on the background thread as normal\n- `stopSensor(sensor: android.hardware.Sensor): void`\n  - Unregisters the sensor.\n- `getDeviceSensors(): android.hardware.Sensor[]`\n  - Returns an array of the devices sensors.\n- `flush(): boolean`\n  - Will flush event data from the listener. Returns true if successful in flushing.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradmartin%2Fnativescript-android-sensors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbradmartin%2Fnativescript-android-sensors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradmartin%2Fnativescript-android-sensors/lists"}