Skip to content

thanush0/InternetSpeedMeter

Repository files navigation

Internet Speed Meter - Android Application

A complete Android application that displays real-time internet speed (download & upload) in the STATUS BAR using a FOREGROUND SERVICE.

📱 Features

  • Real-time Speed Monitoring - Shows download and upload speeds
  • Status Bar Display - Persistent notification with speed info
  • Foreground Service - Runs continuously in background
  • Battery Efficient - Uses Android TrafficStats API
  • Material Design UI - Clean and modern interface
  • Android 13+ Support - Handles runtime permissions
  • Auto-format Speed - Automatically switches between B/s, KB/s, and MB/s
  • Boot Receiver - Optional auto-start on device boot

🔧 Technical Specifications

  • Min SDK: 21 (Android 5.0 Lollipop)
  • Target SDK: 34 (Android 14)
  • Language: Kotlin
  • Architecture: MVVM-ready structure
  • Build System: Gradle 8.2
  • Dependencies: AndroidX, Material Components

📂 Project Structure

InternetSpeedMeter/
├── app/
│   ├── src/
│   │   └── main/
│   │       ├── java/com/speedmeter/app/
│   │       │   ├── MainActivity.kt          # Main UI Activity
│   │       │   ├── SpeedService.kt          # Foreground Service
│   │       │   └── BootReceiver.kt          # Boot auto-start receiver
│   │       ├── res/
│   │       │   ├── drawable/
│   │       │   │   └── ic_speed.xml         # App icon
│   │       │   ├── layout/
│   │       │   │   └── activity_main.xml    # Main UI layout
│   │       │   └── values/
│   │       │       ├── strings.xml          # String resources
│   │       │       ├── colors.xml           # Color palette
│   │       │       └── themes.xml           # App theme
│   │       └── AndroidManifest.xml          # App manifest
│   ├── build.gradle                         # App-level build config
│   └── proguard-rules.pro                   # ProGuard rules
├── gradle/
│   └── wrapper/
│       └── gradle-wrapper.properties        # Gradle wrapper config
├── build.gradle                             # Project-level build config
├── settings.gradle                          # Project settings
├── gradle.properties                        # Gradle properties
└── README.md                                # This file

🚀 Setup Instructions

1. Prerequisites

  • Android Studio Arctic Fox or newer
  • JDK 8 or higher
  • Android SDK with API 34 installed

2. Installation Steps

  1. Open in Android Studio

    File → Open → Select "InternetSpeedMeter" folder
    
  2. Update SDK Path (if needed)

    • Open local.properties
    • Set your Android SDK path:
      sdk.dir=C:\\Users\\YourUsername\\AppData\\Local\\Android\\Sdk
      
  3. Sync Project

    File → Sync Project with Gradle Files
    
  4. Build Project

    Build → Make Project
    
  5. Run on Device

    Run → Run 'app'
    

📋 Permissions

The app requires the following permissions:

  • INTERNET - Required for network access
  • ACCESS_NETWORK_STATE - Check network connectivity
  • FOREGROUND_SERVICE - Run foreground service
  • FOREGROUND_SERVICE_DATA_SYNC - Android 14+ requirement
  • POST_NOTIFICATIONS - Android 13+ notification permission
  • RECEIVE_BOOT_COMPLETED - Auto-start on boot (optional)

🎯 How It Works

1. Speed Calculation Logic

The app uses Android's TrafficStats API to monitor network traffic:

// Get total bytes received/transmitted
val currentRxBytes = TrafficStats.getTotalRxBytes()
val currentTxBytes = TrafficStats.getTotalTxBytes()

// Calculate speed (bytes per second)
val downloadSpeed = (currentRxBytes - previousRxBytes) / timeDiff
val uploadSpeed = (currentTxBytes - previousTxBytes) / timeDiff

2. Foreground Service

The service runs continuously and updates every second:

  • Creates a persistent notification
  • Updates notification with current speed
  • Uses START_STICKY to restart if killed
  • Low importance channel (no sound/vibration)

3. Status Bar Display

Speed format in notification:

↓ 850 KB/s  ↑ 120 KB/s

Auto-formats based on speed:

  • < 1 KB: Shows in B/s
  • < 1 MB: Shows in KB/s
  • ≥ 1 MB: Shows in MB/s (2 decimal places)

📱 Usage

  1. Launch the app
  2. Grant notification permission (Android 13+)
  3. Tap "START SPEED METER"
  4. Check your status bar - Speed appears in notification
  5. Close the app - Service continues running
  6. Tap "STOP SPEED METER" to stop monitoring

⚙️ Configuration Options

Enable Auto-Start on Boot

In BootReceiver.kt, uncomment the code in onReceive():

val serviceIntent = Intent(it, SpeedService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    it.startForegroundService(serviceIntent)
} else {
    it.startService(serviceIntent)
}

Change Update Interval

In SpeedService.kt, modify:

private const val UPDATE_INTERVAL = 1000L // Change to 2000L for 2 seconds

Customize Notification

In SpeedService.kt, update the createInitialNotification() method to change:

  • Title
  • Icon
  • Priority
  • Color

🔒 Battery Optimization

Disable Battery Optimization (Optional)

For best results, users should disable battery optimization:

  1. Settings → Apps → Internet Speed Meter
  2. Battery → Unrestricted

You can guide users programmatically:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    val intent = Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)
    startActivity(intent)
}

🐛 Troubleshooting

Service Stops After Some Time

  • Check battery optimization settings
  • Ensure notification channel is not blocked
  • Verify app has notification permission

Speed Shows 0

  • Check if device has active internet connection
  • VPN might interfere with TrafficStats
  • Some devices don't support TrafficStats properly

Permission Denied

  • Manually grant notification permission in Settings
  • Target SDK must be properly configured

📊 Performance

  • Memory Usage: ~20-30 MB
  • Battery Impact: Minimal (~1-2% per hour)
  • CPU Usage: Very low (updates only once per second)
  • Network Impact: None (only reads system stats)

🎨 Customization

Change App Colors

Edit res/values/colors.xml:

<color name="primary">#2196F3</color>      <!-- Blue -->
<color name="secondary">#F44336</color>    <!-- Red -->

Change App Icon

Replace res/drawable/ic_speed.xml with your custom icon.

Modify UI Layout

Edit res/layout/activity_main.xml to customize the interface.

📄 License

This project is provided as-is for educational and commercial use.

🤝 Contributing

Feel free to improve this project:

  1. Add settings screen for customization
  2. Implement speed history graphs
  3. Add widget support
  4. Export speed logs
  5. Add themes (dark/light mode)

📞 Support

For issues or questions:

  • Check logcat for errors
  • Verify all permissions are granted
  • Test on physical device (not emulator)

✅ Production Checklist

Before releasing to Play Store:

  • Test on multiple devices (Android 5-14)
  • Test with different network conditions
  • Verify notification works correctly
  • Test service survival (force stop, reboot)
  • Check battery optimization behavior
  • Add privacy policy (if collecting data)
  • Create app screenshots
  • Write store description
  • Generate signed APK/AAB

🔄 Version History

Version 1.0

  • Initial release
  • Real-time speed monitoring
  • Foreground service implementation
  • Status bar notification
  • Material Design UI

Made with ❤️ for Android Developers

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages