WhatsApp Status Saver App Source Code Thumbnail

How to Make WhatsApp Status Saver App for Android Using Kotlin

WhatsApp statuses are a popular way to share moments with your friends and family. However, these statuses tend to disappear after 24 hours. If you want to save your favorite statuses, or those of your contacts, you can create a WhatsApp Status Saver app using Kotlin and the Model-View-ViewModel (MVVM) architectural pattern. In this article, we will guide you through the process of building such an app step by step.

Setup Project

To get started first let’s setup project. First of all include the following libraries in project

    implementation("com.jsibbold:zoomage:1.3.1")
    implementation("androidx.media3:media3-exoplayer:1.1.1")
    implementation("androidx.media3:media3-exoplayer-dash:1.1.1")
    implementation("androidx.media3:media3-ui:1.1.1")
    implementation ("androidx.documentfile:documentfile:1.0.1")
    implementation ("com.github.bumptech.glide:glide:4.15.1")
    implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01")

You can also download initial project (Click here to download).

Function to save status

fun Context.saveStatus(model: MediaModel): Boolean {
    if (isStatusExist(model.fileName)){
        return true
    }
    val extension = getFileExtension(model.fileName)
    val mimeType = "${model.type}/$extension"
    val inputStream = contentResolver.openInputStream(model.pathUri.toUri())
    try {
        val values = ContentValues()
        values.apply {
            put(MediaStore.MediaColumns.MIME_TYPE, mimeType)
            put(MediaStore.MediaColumns.DISPLAY_NAME, model.fileName)
            put(
                MediaStore.MediaColumns.RELATIVE_PATH,
                Environment.DIRECTORY_DOCUMENTS + "/" + getString(R.string.app_name)
            )
        }
        val uri = contentResolver.insert(
            MediaStore.Files.getContentUri("external"),
            values
        )
        uri?.let {
            val outputStream = contentResolver.openOutputStream(it)
            if (inputStream != null) {
                outputStream?.write(inputStream.readBytes())
            }
            outputStream?.close()
            inputStream?.close()
            return true
        }
    } catch (e: Exception) {
        e.printStackTrace()
    }
    return false
}

Leave a Reply

Your email address will not be published. Required fields are marked *