[카테고리:] 미분류

  • Android Storage Info App Guide

    I’ve created a simple Android application that displays internal storage information directly on your device. If you’re an Android developer looking to implement storage monitoring functionality in your apps, this project provides a clean example using Jetpack Compose.

    Project Overview

    The Storage Info App offers a straightforward way to view:

    • Total internal storage capacity
    • Used storage space
    • Free storage space
    • Usage percentage with a visual progress indicator

    Key Technical Features

    • Modern UI with Jetpack Compose: Uses declarative UI paradigm for building the interface
    • Storage Access APIs: Demonstrates how to access device storage information using Android’s StatFs class
    • Runtime Permissions: Properly requests and handles storage access permissions
    • Responsive Layout: Works across different device sizes and orientations
    • Kotlin Coroutines: For smooth background operations

    Implementation Details

    The app uses Android’s StatFs class to retrieve storage metrics for the device’s internal storage. This information is displayed through a clean Compose UI with a refresh button that allows users to update the data on demand.

    Key code snippets:

    // Getting total storage capacity
    private fun getTotalBytes(path: File): Long {
        val stats = StatFs(path.path)
        return stats.totalBytes
    }
    
    // Getting available storage
    private fun getFreeBytes(path: File): Long {
        val stats = StatFs(path.path)
        return stats.availableBytes
    }
    

    Getting Started

    1. Clone the repository: git clone https://github.com/hajunho/naver.how.util.android.istf_storage.git
    2. Open the project in Android Studio
    3. Build and run on an Android device or emulator (Android 8.0/API 26 or higher)

    Requirements

    • Android Studio Hedgehog or higher
    • Kotlin 1.9.0+
    • Android 8.0+ (API level 26+)

    Permissions

    The app requires the following permission:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    

    For Android 11+ (API 30+), more granular permissions would be implemented in a production app.

    Technical Considerations

    When implementing storage monitoring in your own apps, keep these points in mind:

    1. API Level Compatibility: Different Android versions may require different approaches to accessing storage
    2. Permission Handling: Always implement proper permission requests and handle denials gracefully
    3. Storage Types: Consider both internal and external storage if needed
    4. Updates: Storage information should be refreshed when the app resumes or when requested by the user

    License

    This project is available as open source.

    Feel free to contribute to the project or use it as a reference for implementing storage monitoring in your own Android applications!