Skip to content

chrimaeon/app-rater

Repository files navigation

Android™ App Rater Dialog Build & test

License MavenCentral

This is a App Rater Dialog to encourage user to rate the app

Usage

Add the following dependency to your build.gradle.

dependencies {
    implementation 'com.cmgapps.android:app-rater:3.2.0'
}

Extend the Application class and register a LifecycleObserver

import android.app.Application
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.lifecycle.ProcessLifecycleOwner
import com.cmgapps.android.apprater.AppRater

class SampleApp : Application() {

    override fun onCreate() {
        super.onCreate()
        val appRater = AppRater.Builder(this).build()
        ProcessLifecycleOwner.get().lifecycle.addObserver(AppLifecycleListener(apprater))

    }
}

class AppLifecycleListener(private val appRater: AppRater) : LifecycleObserver {

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    fun onAppForeground() {
        appRater.incrementUseCount()
    }
}

and in your main Activity#onCreate check if requirements for rating are met and show the dialog

override fun onCreate(savedInstanceState: Bundle) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    val appRater = AppRater.Builder(this).build()

    if (mAppRater.checkForRating()) {
        mAppRater.show(this)
    }
}

See the Sample App (/sample) for a reference implementation

Kotlin Extension

Add the following dependency to your build.gradle.

dependencies {
    implementation 'com.cmgapps.android:app-rater-ktx:3.2.0'
}

You can now configure and create the App Rater using a DSL

override fun onCreate() {
    super.onCreate()
    val appRater = appRater(this) {
        daysUntilPrompt(3)
        launchesUntilPrompt(10)
    }
}

License

Copyright 2016-2021 Christian Grach

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Android is a trademark of Google Inc.