{"id":4609,"url":"https://github.com/oojr/react-native-battery","last_synced_at":"2025-08-04T01:32:39.958Z","repository":{"id":57335675,"uuid":"42564630","full_name":"oojr/react-native-battery","owner":"oojr","description":"plugin for react native that adds an listener for the battery status of a device","archived":false,"fork":false,"pushed_at":"2020-02-04T10:04:47.000Z","size":249,"stargazers_count":51,"open_issues_count":2,"forks_count":25,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-26T03:35:33.162Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oojr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-16T04:31:37.000Z","updated_at":"2024-04-09T05:26:10.000Z","dependencies_parsed_at":"2022-09-07T16:34:15.286Z","dependency_job_id":null,"html_url":"https://github.com/oojr/react-native-battery","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/oojr/react-native-battery","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oojr%2Freact-native-battery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oojr%2Freact-native-battery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oojr%2Freact-native-battery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oojr%2Freact-native-battery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oojr","download_url":"https://codeload.github.com/oojr/react-native-battery/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oojr%2Freact-native-battery/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268636421,"owners_count":24282089,"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","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-01-05T20:17:17.802Z","updated_at":"2025-08-04T01:32:39.645Z","avatar_url":"https://github.com/oojr.png","language":"Java","funding_links":[],"categories":["Components","\u003ca name=\"OS-\u0026-System-\u0026-File-Manager:-Native-Modules\"\u003eOS, System \u0026 File Manager: Native Modules\u003c/a\u003e"],"sub_categories":["System"],"readme":"# react-native-battery\n\nA cross-platform React Native module that returns the battery level/status of a device. Supports iOS and Android.\n\n## Package Installation\n`npm install react-native-battery --save`\n\n### iOS automatic setup\n*   `react-native link react-native-battery`\n\n\n### Android setup\n*   `react-native link react-native-battery` may work, but it sometimes munges files. If automatic installation fails, use the following manual steps.\n*   Add to `MainApplication.java`:\n```\nimport com.rctbattery.BatteryManagerPackage;\n// ...\n\n@Override\nprotected List\u003cReactPackage\u003e getPackages() {\n  return Arrays.\u003cReactPackage\u003easList(\n      new MainReactPackage(),\n        new BatteryManagerPackage(),\n        // ...\n  );\n}\n```\n*   Add to `android/settings.gradle`:\n```\ninclude ':react-native-battery'\nproject(':react-native-battery').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-battery/android')\n//...\n```\n*   Add to `android/app/build.gradle`:\n```\ndependencies {\n  compile project(':react-native-battery')\n  //...\n}\n```\n\n\n## Example\n```javascript\n'use strict';\nvar React = require('react-native');\nvar BatteryManager = require('NativeModules').BatteryManager;\nvar {\n  AppRegistry,\n  StyleSheet,\n  Text,\n  View,\n  DeviceEventEmitter,\n} = React;\n\nvar RCTBattery = React.createClass({\n\n  getInitialState: function() {\n    return {batteryLevel: null, charging:false};\n  },\n\n  onBatteryStatus: function(info){\n    this.setState({batteryLevel: info.level});\n    this.setState({charging: info.isPlugged});\n  },\n\n  componentDidMount: function(){\n    BatteryManager.updateBatteryLevel(function(info){\n      this._subscription = DeviceEventEmitter.addListener('BatteryStatus', this.onBatteryStatus);\n      this.setState({batteryLevel: info.level});\n      this.setState({charging: info.isPlugged});\n    }.bind(this));\n  },\n\n  componentWillUnmount: function(){\n    this._subscription.remove();\n  },\n\n  render: function() {\n    var chargingText;\n    if(this.state.charging){\n      chargingText =\u003cText style={styles.instructions}\u003eCharging \u003c/Text\u003e;\n    } else {\n      chargingText =\u003cText style={styles.instructions}\u003eNot Charging \u003c/Text\u003e;\n    }\n    return (\n      \u003cView style={styles.container}\u003e\n        \u003cText style={styles.welcome}\u003e\n          Battery Level {this.state.batteryLevel}\n        \u003c/Text\u003e\n        {chargingText}\n      \u003c/View\u003e\n    );\n  }\n});\n\nvar styles = StyleSheet.create({\n  container: {\n    flex: 1,\n    justifyContent: 'center',\n    alignItems: 'center',\n    backgroundColor: '#F5FCFF',\n  },\n  welcome: {\n    fontSize: 20,\n    textAlign: 'center',\n    margin: 10,\n  },\n  instructions: {\n    textAlign: 'center',\n    color: '#333333',\n    marginBottom: 5,\n  },\n});\n\nAppRegistry.registerComponent('RCTBattery', () =\u003e RCTBattery);\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foojr%2Freact-native-battery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foojr%2Freact-native-battery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foojr%2Freact-native-battery/lists"}