This Android project demonstrates how to track and display the network connection status using Jetpack Compose. It includes a custom ConnectionManager
class that uses StateFlow
to observe network connectivity changes and updates the UI accordingly.
- Live Network Monitoring: The app listens for network connectivity changes in real-time.
- Jetpack Compose UI: The UI dynamically updates to reflect the online/offline status.
- Animated UI Transitions: Smooth color and icon transitions are used to indicate the change in network status.
-
ConnectionManager: This class uses
ConnectivityManager
andcallbackFlow
to monitor network changes and emits the network status as aStateFlow<Boolean>
. -
MainActivity: Subscribes to the network status using
collectAsState()
and updates theHomeScreen
composable based on the current connection status. -
HomeScreen Composable: Displays a card with a message and an icon, both of which animate smoothly when the network status changes.
- Android Studio: Arctic Fox or later
- Kotlin: 1.5 or later
- Jetpack Compose: 1.0.0 or later
- Clone this repository to your local machine.
git clone https://github.com/your-username/network-connection-status.git
- Open the project in Android Studio.
- Build and run the app on an emulator or physical device.
You can watch the demo video below to see the app in action: