{"id":17713565,"url":"https://github.com/shubhamsinghshubham777/composebroadcasts","last_synced_at":"2025-05-07T22:29:04.623Z","repository":{"id":259272408,"uuid":"871687769","full_name":"shubhamsinghshubham777/ComposeBroadcasts","owner":"shubhamsinghshubham777","description":"Consume Android's Broadcast Receivers in a fun and easy way from your Jetpack Composables 📡","archived":false,"fork":false,"pushed_at":"2025-05-07T07:35:02.000Z","size":491,"stargazers_count":31,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T08:34:51.699Z","etag":null,"topics":["android","android-library","broadcast-reciever","jetpack-compose","kotlin-library"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/shubhamsinghshubham777.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-10-12T16:56:14.000Z","updated_at":"2025-05-07T07:35:01.000Z","dependencies_parsed_at":"2024-10-24T02:21:24.682Z","dependency_job_id":"aad49cfb-d4bd-49a2-8f30-257bfab69026","html_url":"https://github.com/shubhamsinghshubham777/ComposeBroadcasts","commit_stats":null,"previous_names":["shubhamsinghshubham777/composebroadcasts"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamsinghshubham777%2FComposeBroadcasts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamsinghshubham777%2FComposeBroadcasts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamsinghshubham777%2FComposeBroadcasts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamsinghshubham777%2FComposeBroadcasts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shubhamsinghshubham777","download_url":"https://codeload.github.com/shubhamsinghshubham777/ComposeBroadcasts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252964358,"owners_count":21832673,"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","android-library","broadcast-reciever","jetpack-compose","kotlin-library"],"created_at":"2024-10-25T10:05:20.914Z","updated_at":"2025-05-07T22:29:04.600Z","avatar_url":"https://github.com/shubhamsinghshubham777.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--suppress CheckImageSize --\u003e\n\u003ch1 align=\"center\"\u003eCompose Broadcasts\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"assets/logo.svg\" width=250 alt=\"Compose Broadcasts Logo\" /\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Jetpack%20Compose-purple?style=for-the-badge\" alt=\"Compose Badge\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Android-3DDC84?style=for-the-badge\u0026logo=android\u0026logoColor=white\" alt=\"Android Badge\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Kotlin-0095D5?\u0026style=for-the-badge\u0026logo=kotlin\u0026logoColor=white\" alt=\"Kotlin Badge\" /\u003e\n\u003c/p\u003e\n\n## 🚀 Introduction\n\nCompose Broadcasts is a powerful Jetpack Compose library that simplifies the process of working with\nAndroid's BroadcastReceivers in a composable environment. It provides an intuitive API to observe\nand react to system-wide events and changes in your Compose UI.\n\n## ✨ Features\n\n- 🔄 Easy integration with Jetpack Compose\n- 📡 Observe system events like battery level, airplane mode, and more\n- 🎛️ Custom BroadcastReceiver support\n- 🧩 Composable functions for common system events\n- 🛠️ Flexible API for creating custom broadcast listeners\n- ☮️ No need to worry about registering / unregistering listeners anymore\n\n## 📦 Installation\n\n\u003cimg alt=\"Sonatype Nexus (Releases)\" src=\"https://img.shields.io/nexus/r/io.github.shubhamsinghshubham777/composebroadcasts?server=https%3A%2F%2Fs01.oss.sonatype.org\u0026style=for-the-badge\"\u003e\n\nAdd the following to your app's `build.gradle.kts`:\n\n```kotlin\n// Get the latest version from GitHub Releases/Tags\nimplementation(\"io.github.shubhamsinghshubham777:composebroadcasts:0.0.1\")\n```\n\n### For SNAPSHOT versions\n\nAdd the following to your project level `settings.gradle.kts`:\n\n```kotlin\ndependencyResolutionManagement {\n    repositories {\n        ...\n        // Add this\n        maven(\"https://s01.oss.sonatype.org/content/repositories/snapshots/\")\n    }\n}\n```\n\n## 🛠️ Usage\n\nHere's the complete list of composables Compose Broadcasts provides at the moment:\n\n| **Composable**                   | **Return Type**    |\n|----------------------------------|--------------------|\n| rememberBroadcastReceiverAsState | Generic (T)        |\n| rememberIsAirplaneModeOn         | Boolean            |\n| rememberBatteryLevel             | Int                |\n| rememberIsCharging               | Boolean            |\n| rememberPackageInfo              | CBPackageInfo?     |\n| rememberCurrentTimeMillis        | Long               |\n| rememberSystemLocale             | Locale             |\n| rememberIsScreenOn               | Boolean            |\n| rememberIsHeadsetConnected       | Boolean            |\n| rememberCurrentInputMethod       | CBInputMethodInfo? |\n\nAnd here are some examples of how to use them in your project:\n\n### Observe Airplane Mode\n\n```kotlin\nval isAirplaneModeOn by rememberIsAirplaneModeOn()\nText(\"Airplane mode is ${if (isAirplaneModeOn) \"ON\" else \"OFF\"}\")\n```\n\n### Monitor Battery Level\n\n```kotlin\nval batteryLevel by rememberBatteryLevel()\nText(\"Current battery level: $batteryLevel%\")\n```\n\n### Track Device Charging Status\n\n```kotlin\nval isCharging by rememberIsCharging()\nText(\"Device is ${if (isCharging) \"charging\" else \"not charging\"}\")\n```\n\n### Observe Package Changes\n\nCheck out the [🧩 Custom BroadcastReceivers](#-custom-broadcastreceivers) section below to learn\nhow to create PackageInfoReceiver.\n\n```kotlin\nval packageInfoReceiver = PackageInfoReceiver()\nval packageInfo by rememberPackageInfo(packageInfoReceiver)\nText(\"Last package change: $packageInfo\")\n```\n\n### Monitor System Time\n\n```kotlin\nval currentTimeMillis by rememberCurrentTimeMillis()\nText(\"Current time: ${convertMillisToTimeString(currentTimeMillis)}\")\n```\n\n### Track System Locale Changes\n\nCheck out the [🧩 Custom BroadcastReceivers](#-custom-broadcastreceivers) section below to learn\nhow to create LocaleReceiver.\n\n```kotlin\nval localeReceiver = LocaleReceiver()\nval currentLocale by rememberSystemLocale(localeReceiver)\nText(\"Current system locale: ${currentLocale.toLanguageTag()}\")\n```\n\n## 🧩 Custom BroadcastReceivers\n\nYou can create custom BroadcastReceivers by extending the `CBBroadcastReceiver` class:\n\n```kotlin\nclass MyCustomReceiver : CBBroadcastReceiver(tag = \"my_custom_receiver\") {\n    override fun onReceive(context: Context?, intent: Intent?) {\n        super.onReceive(context, intent)\n        // Your custom logic here (if you like the old way of writing receivers)\n        // Ideally, your logic should be a part of the composable itself\n        // This class should just be left blank, for example:\n        // class MyCustomReceiver : CBBroadcastReceiver(tag = \"my_custom_receiver\")\n    }\n}\n```\n\nThen, register the receiver in your AndroidManifest.xml file:\n\n```xml\n\n\u003cmanifest\u003e\n    \u003capplication\u003e\n        \u003creceiver android:name=\".MyCustomReceiver\" android:exported=\"false\"\u003e\n            \u003cintent-filter\u003e\n                \u003c!-- Example: android.intent.action.PACKAGE_ADDED --\u003e\n                \u003caction android:name=\"YOUR_CUSTOM_ACTION\" /\u003e\n            \u003c/intent-filter\u003e\n        \u003c/receiver\u003e\n    \u003c/application\u003e\n\u003c/manifest\u003e\n```\n\nFinally, use it in your composable:\n\n```kotlin\nval customState by rememberBroadcastReceiverAsState(\n    initialValue = initialState,\n    // Example: CBIntentAction.Custom(Intent.ACTION_PACKAGE_ADDED)\n    intentFilters = listOf(CBIntentFilter(CBIntentAction.Custom(\"YOUR_CUSTOM_ACTION\"))),\n    broadcastReceiver = MyCustomReceiver(),\n) { context, intent -\u003e\n    // Map the received intent to your state\n}\n```\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## 📄 License\n\nThis library is licensed under the Apache 2.0 License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshubhamsinghshubham777%2Fcomposebroadcasts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshubhamsinghshubham777%2Fcomposebroadcasts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshubhamsinghshubham777%2Fcomposebroadcasts/lists"}