A lightweight Android utility by Refat that displays real-time internet download speed directly in the device status bar using a persistent foreground service and dynamic notification icons.
- Overview
- Architecture
- Project Structure
- Requirements
- Setup
- Build & Run
- APK Deployment
- Security Model
- Known Limitations
Net Meter works by reading Android's TrafficStats API every second to calculate the bytes downloaded since the last tick, formatting the result into a compact string (e.g. 120K, 1.5M), and drawing it onto a Bitmap that is set as the notification's small icon — causing the speed to appear in the status bar.
MainActivity ──► NetMeterService (Foreground Service)
│
├── TrafficStats (Android API)
├── SpeedFormatter (utils)
└── NotificationManager (Android API)
| Layer | File | Responsibility |
|---|---|---|
| UI | MainActivity.kt |
Toggle switch, runtime permission request |
| Service | NetMeterService.kt |
Speed polling loop, notification updates |
| Utility | SpeedFormatter.kt |
Byte-to-string conversion (KB/s, MB/s) |
RefatSpeedMeter/
├── build.gradle.kts
├── settings.gradle.kts
├── README.md
├── CHANGELOG.md
├── DEPLOYMENT.md
└── app/
├── build.gradle.kts
├── proguard-rules.pro
└── src/main/
├── AndroidManifest.xml
└── java/com/refat/netmeter/
├── MainActivity.kt
├── service/
│ └── NetMeterService.kt
└── utils/
└── SpeedFormatter.kt
| Tool | Version |
|---|---|
| Android Studio | Hedgehog (2023.1.1) or newer |
| Android Gradle Plugin | 8.3.0 |
| Kotlin | 1.9.23 |
| Java | 11 |
compileSdk |
35 |
minSdk |
26 (Android 8.0 Oreo) |
targetSdk |
35 |
- Clone or download the repository into a local folder.
- Open Android Studio →
File→Open→ selectRefatSpeedMeter/. - Let Gradle sync complete. All dependencies are fetched automatically from Maven Central and Google.
- Connect a physical device or start an emulator running API 26+.
In Android Studio, press Run ▶ or use the terminal:
./gradlew assembleDebugThe debug APK is output to:
app/build/outputs/apk/debug/app-debug.apk
./gradlew installDebugSee DEPLOYMENT.md for the full step-by-step release process including signing, ProGuard, and Google Play submission.
Net Meter uses a two-layer security model to prevent unauthorised processes from starting or interacting with NetMeterService:
android:exported="false"— the service is invisible to all other apps at the OS level.- Signature permission (
com.refat.netmeter.permission.NET_METER_SERVICE,protectionLevel="signature") — only APKs signed with the same release keystore can hold this permission. The service verifies it explicitly viacheckCallingOrSelfPermissioninonCreateandcheckSelfPermissioninMainActivitybefore any operation is performed.
- Status bar space — Android does not guarantee how many notification icons are visible. On heavily customised ROMs (MIUI, One UI), the icon may be hidden by the manufacturer's status bar policy.
- Battery optimisation — Aggressive battery savers (e.g. Huawei, Xiaomi) may pause the coroutine loop when the screen is off for extended periods. Guide users to exempt the app from battery optimisation in device settings.
TrafficStatsaccuracy — The API measures all network traffic on the device (across all apps). It does not isolate per-app traffic.- Upload speed — The current implementation only tracks
RxBytes(download). Upload tracking viaTxBytesis not yet implemented.