├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .DS_Store ├── build.gradle ├── gradle.properties └── src │ ├── .DS_Store │ └── main │ ├── .DS_Store │ ├── AndroidManifest.xml │ └── java │ ├── .DS_Store │ └── com │ ├── .DS_Store │ └── grizzlynt │ ├── .DS_Store │ └── reviews │ ├── GNTReviewManager.java │ └── GNTReviewPreferenceHelper.java ├── sample ├── build.gradle └── src │ └── main │ └── AndroidManifest.xml └── settings.gradle /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Grizzly New Technologies GmbH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Library to wrap Google's new in-app reviews-feature, which let you rate apps without switching to the Play Store! 2 | 3 | [![](https://jitpack.io/v/grizzly/android-in-app-reviews.svg)](https://jitpack.io/#grizzly/android-in-app-reviews) 4 | 5 | ## Other Version 6 | 7 | Flutter: https://pub.dev/packages/advanced_in_app_review 8 | 9 | iOS: https://github.com/grizzly/AppRating 10 | 11 | ## Install 12 | 13 | ### Step 1 Add the JitPack repository to your build file 14 | 15 | ```groovy 16 | allprojects { 17 | repositories { 18 | maven { url 'https://jitpack.io' } 19 | } 20 | } 21 | ``` 22 | 23 | ### Step 2 Add the dependency 24 | 25 | ```groovy 26 | dependencies { 27 | implementation 'com.github.grizzly:android-in-app-reviews:{latest.version}' 28 | } 29 | ``` 30 | 31 | ## Important 32 | 33 | Google encourages developers not to spam users with review requests right when they first start an app, instead asking studios to prompt people only after they've used the application for a while. Developers also shouldn't interrupt users in the middle of a task. After leaving a review or aborting, people should be able to continue whatever they were doing seamlessly. 34 | 35 | Android decides when and if such a review view will be presented to the user. So please do not wonder if the view is not presented during debugging. As Google also noted, it will not be working in debug mode. Please see https://developer.android.com/guide/playcore/in-app-review/test 36 | 37 | ## Usage 38 | 39 | ### Configuration 40 | 41 | Android In-App-Reviews provides methods to configure its behavior. 42 | 43 | ```java 44 | @Override 45 | protected void onCreate(Bundle savedInstanceState) { 46 | super.onCreate(savedInstanceState); 47 | setContentView(R.layout.activity_main); 48 | 49 | GNTReviewManager.with(this) 50 | .setInstallDays(2) // default 10, 0 means install day. 51 | .setLaunchTimes(3) // default 10 52 | .setRemindInterval(2) // default 1 53 | .setDebug(false) // default false 54 | .monitor(); 55 | 56 | // Show a dialog if meets conditions 57 | GNTReviewManager.showRateDialogIfMeetsConditions(this); 58 | } 59 | ``` 60 | 61 | ## Testing 62 | 63 | Testing can be done on testing tracks in Google Play — Internal Testing, Alpha, or Beta. Publish your app there and make sure that your current Google Account hasn’t reviewed the app yet. There are no quotas in testing tracks, so you will always see the dialog. If you send a rating, it won’t be added as a review but as a testing feedback. 64 | 65 | ## Contribute 66 | 67 | 1. Fork it 68 | 2. Create your feature branch (`git checkout -b my-new-feature`) 69 | 3. Commit your changes (`git commit -am 'Added some feature'`) 70 | 4. Push to the branch (`git push origin my-new-feature`) 71 | 5. Create new Pull Request 72 | 73 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | 2 | buildscript { 3 | repositories { 4 | jcenter() 5 | google() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:3.5.1' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | mavenCentral() 15 | google() 16 | jcenter() 17 | maven { url "https://jitpack.io" } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | VERSION_NAME=1.0.0 2 | VERSION_CODE=1 3 | GROUP=com.github.grizzly 4 | POM_DESCRIPTION=Library for Android applications to show in app ratings dialog. 5 | POM_URL=https://github.com/grizzly/android-in-app-reviews.git 6 | POM_SCM_URL=https://github.com/grizzly/android-in-app-reviews.git 7 | POM_SCM_CONNECTION=scm:git@github.com:grizzly/android-in-app-reviews.git 8 | POM_SCM_DEV_CONNECTION=scm:git@github.com:grizzly/android-in-app-reviews.git 9 | POM_LICENCE_NAME=The MIT License 10 | POM_LICENCE_URL=http://opensource.org/licenses/mit-license.php 11 | POM_LICENCE_DIST=repo 12 | POM_DEVELOPER_ID=grizzly 13 | POM_DEVELOPER_NAME=Stefan Mayr 14 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grizzly/android-in-app-reviews/160f19eec31c4f327c92c217a32cc82a34ca4324/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /library/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grizzly/android-in-app-reviews/160f19eec31c4f327c92c217a32cc82a34ca4324/library/.DS_Store -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | repositories { 4 | mavenCentral() 5 | google() 6 | jcenter() 7 | maven { url "https://jitpack.io" } 8 | } 9 | 10 | android { 11 | 12 | compileSdkVersion 29 13 | buildToolsVersion "29.0.0" 14 | defaultConfig { 15 | minSdkVersion 21 16 | targetSdkVersion 29 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | } 23 | } 24 | 25 | compileOptions { 26 | sourceCompatibility JavaVersion.VERSION_1_8 27 | targetCompatibility JavaVersion.VERSION_1_8 28 | } 29 | } 30 | 31 | 32 | dependencies { 33 | api 'com.google.android.play:core:1.8.0' 34 | } 35 | 36 | task sourcesJar(type: Jar) { 37 | classifier = 'sources' 38 | from android.sourceSets.main.java.sourceFiles 39 | } 40 | 41 | task classesJar(type: Jar) { 42 | from "$buildDir/intermediates/classes/release" 43 | } 44 | 45 | artifacts { 46 | archives classesJar 47 | archives sourcesJar 48 | } 49 | -------------------------------------------------------------------------------- /library/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=Android-In-App-Reviews 2 | POM_ARTIFACT_ID=android-in-app-reviews 3 | POM_PACKAGING=aar 4 | -------------------------------------------------------------------------------- /library/src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grizzly/android-in-app-reviews/160f19eec31c4f327c92c217a32cc82a34ca4324/library/src/.DS_Store -------------------------------------------------------------------------------- /library/src/main/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grizzly/android-in-app-reviews/160f19eec31c4f327c92c217a32cc82a34ca4324/library/src/main/.DS_Store -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /library/src/main/java/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grizzly/android-in-app-reviews/160f19eec31c4f327c92c217a32cc82a34ca4324/library/src/main/java/.DS_Store -------------------------------------------------------------------------------- /library/src/main/java/com/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grizzly/android-in-app-reviews/160f19eec31c4f327c92c217a32cc82a34ca4324/library/src/main/java/com/.DS_Store -------------------------------------------------------------------------------- /library/src/main/java/com/grizzlynt/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grizzly/android-in-app-reviews/160f19eec31c4f327c92c217a32cc82a34ca4324/library/src/main/java/com/grizzlynt/.DS_Store -------------------------------------------------------------------------------- /library/src/main/java/com/grizzlynt/reviews/GNTReviewManager.java: -------------------------------------------------------------------------------- 1 | package com.grizzlynt.reviews; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.os.Handler; 6 | 7 | import com.google.android.play.core.review.ReviewInfo; 8 | import com.google.android.play.core.review.ReviewManager; 9 | import com.google.android.play.core.review.ReviewManagerFactory; 10 | import com.google.android.play.core.tasks.Task; 11 | 12 | import java.util.Date; 13 | 14 | import static com.grizzlynt.reviews.GNTReviewPreferenceHelper.getInstallDate; 15 | import static com.grizzlynt.reviews.GNTReviewPreferenceHelper.getLaunchTimes; 16 | import static com.grizzlynt.reviews.GNTReviewPreferenceHelper.getRemindInterval; 17 | import static com.grizzlynt.reviews.GNTReviewPreferenceHelper.isFirstLaunch; 18 | import static com.grizzlynt.reviews.GNTReviewPreferenceHelper.setInstallDate; 19 | import static com.grizzlynt.reviews.GNTReviewPreferenceHelper.setRemindIntervalDate; 20 | 21 | 22 | public class GNTReviewManager { 23 | 24 | private static GNTReviewManager singleton; 25 | 26 | private final Context context; 27 | 28 | private int installDate = 10; 29 | 30 | private int launchTimes = 10; 31 | 32 | private int remindInterval = 1; 33 | 34 | private boolean isDebug = false; 35 | 36 | private GNTReviewManager(Context context) { 37 | this.context = context.getApplicationContext(); 38 | } 39 | 40 | public static GNTReviewManager with(Context context) { 41 | if (singleton == null) { 42 | synchronized (GNTReviewManager.class) { 43 | if (singleton == null) { 44 | singleton = new GNTReviewManager(context); 45 | } 46 | } 47 | } 48 | return singleton; 49 | } 50 | 51 | public static boolean showRateDialogIfMeetsConditions(Activity activity) { 52 | boolean isMeetsConditions = singleton.isDebug || singleton.shouldShowRateDialog(); 53 | if (isMeetsConditions) { 54 | singleton.showRateDialog(activity); 55 | } 56 | return isMeetsConditions; 57 | } 58 | 59 | private static boolean isOverDate(long targetDate, int threshold) { 60 | return new Date().getTime() - targetDate >= threshold * 24 * 60 * 60 * 1000; 61 | } 62 | 63 | public GNTReviewManager setLaunchTimes(int launchTimes) { 64 | this.launchTimes = launchTimes; 65 | return this; 66 | } 67 | 68 | public GNTReviewManager setInstallDays(int installDate) { 69 | this.installDate = installDate; 70 | return this; 71 | } 72 | 73 | public GNTReviewManager setRemindInterval(int remindInterval) { 74 | this.remindInterval = remindInterval; 75 | return this; 76 | } 77 | 78 | public void monitor() { 79 | if (isFirstLaunch(context)) { 80 | setInstallDate(context); 81 | } 82 | GNTReviewPreferenceHelper.setLaunchTimes(context, getLaunchTimes(context) + 1); 83 | } 84 | 85 | public void showRateDialog(Activity activity) { 86 | if (!activity.isFinishing()) { 87 | final Handler handler = new Handler(); 88 | handler.postDelayed(new Runnable() { 89 | @Override 90 | public void run() { 91 | showDialog(activity); 92 | } 93 | }, 5000); 94 | } 95 | } 96 | 97 | public boolean shouldShowRateDialog() { 98 | return isOverLaunchTimes() && 99 | isOverInstallDate() && 100 | isOverRemindDate(); 101 | } 102 | 103 | private boolean isOverLaunchTimes() { 104 | return getLaunchTimes(context) >= launchTimes; 105 | } 106 | 107 | private boolean isOverInstallDate() { 108 | return isOverDate(getInstallDate(context), installDate); 109 | } 110 | 111 | private boolean isOverRemindDate() { 112 | return isOverDate(getRemindInterval(context), remindInterval); 113 | } 114 | 115 | public boolean isDebug() { 116 | return isDebug; 117 | } 118 | 119 | public GNTReviewManager setDebug(boolean isDebug) { 120 | this.isDebug = isDebug; 121 | return this; 122 | } 123 | 124 | public void showDialog(Activity activity) { 125 | ReviewManager manager = ReviewManagerFactory.create(context); 126 | Task request = manager.requestReviewFlow(); 127 | 128 | request.addOnCompleteListener(task -> { 129 | if (task.isSuccessful()) { 130 | // We can get the ReviewInfo object 131 | ReviewInfo reviewInfo = task.getResult(); 132 | startReview(activity, manager, reviewInfo); 133 | } else { 134 | // There was some problem, continue regardless of the result. 135 | setRemindIntervalDate(context); 136 | } 137 | }); 138 | } 139 | 140 | public void startReview(Activity activity, ReviewManager manager, ReviewInfo reviewInfo) { 141 | Task flow = manager.launchReviewFlow(activity, reviewInfo); 142 | flow.addOnCompleteListener(task -> { 143 | // The flow has finished. The API does not indicate whether the user 144 | // reviewed or not, or even whether the review dialog was shown. Thus, no 145 | // matter the result, we continue our app flow. 146 | setRemindIntervalDate(context); 147 | }); 148 | } 149 | 150 | } 151 | 152 | -------------------------------------------------------------------------------- /library/src/main/java/com/grizzlynt/reviews/GNTReviewPreferenceHelper.java: -------------------------------------------------------------------------------- 1 | package com.grizzlynt.reviews; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | import java.util.Date; 7 | 8 | 9 | final class GNTReviewPreferenceHelper { 10 | 11 | private static final String PREF_FILE_NAME = "android_rate_pref_file"; 12 | 13 | private static final String PREF_KEY_INSTALL_DATE = "android_rate_install_date"; 14 | 15 | private static final String PREF_KEY_LAUNCH_TIMES = "android_rate_launch_times"; 16 | 17 | private static final String PREF_KEY_REMIND_INTERVAL = "android_rate_remind_interval"; 18 | 19 | private GNTReviewPreferenceHelper() { 20 | } 21 | 22 | static SharedPreferences getPreferences(Context context) { 23 | return context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE); 24 | } 25 | 26 | static SharedPreferences.Editor getPreferencesEditor(Context context) { 27 | return getPreferences(context).edit(); 28 | } 29 | 30 | /** 31 | * Clear data in shared preferences.
32 | * 33 | * @param context context 34 | */ 35 | static void setRemindIntervalDate(Context context) { 36 | SharedPreferences.Editor editor = getPreferencesEditor(context); 37 | editor.remove(PREF_KEY_REMIND_INTERVAL); 38 | editor.putLong(PREF_KEY_REMIND_INTERVAL, new Date().getTime()); 39 | editor.apply(); 40 | } 41 | 42 | static long getRemindInterval(Context context) { 43 | return getPreferences(context).getLong(PREF_KEY_REMIND_INTERVAL, 0); 44 | } 45 | 46 | static void setInstallDate(Context context) { 47 | SharedPreferences.Editor editor = getPreferencesEditor(context); 48 | editor.putLong(PREF_KEY_INSTALL_DATE, new Date().getTime()); 49 | editor.apply(); 50 | } 51 | 52 | static long getInstallDate(Context context) { 53 | return getPreferences(context).getLong(PREF_KEY_INSTALL_DATE, 0); 54 | } 55 | 56 | static void setLaunchTimes(Context context, int launchTimes) { 57 | SharedPreferences.Editor editor = getPreferencesEditor(context); 58 | editor.putInt(PREF_KEY_LAUNCH_TIMES, launchTimes); 59 | editor.apply(); 60 | } 61 | 62 | static int getLaunchTimes(Context context) { 63 | return getPreferences(context).getInt(PREF_KEY_LAUNCH_TIMES, 0); 64 | } 65 | 66 | static boolean isFirstLaunch(Context context) { 67 | return getPreferences(context).getLong(PREF_KEY_INSTALL_DATE, 0) == 0L; 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion '29.0.2' 6 | 7 | defaultConfig { 8 | applicationId "com.grizzlynt.android.review" 9 | minSdkVersion 21 10 | targetSdkVersion 29 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | 15 | compileOptions { 16 | sourceCompatibility 1.8 17 | targetCompatibility 1.8 18 | } 19 | } 20 | 21 | repositories { 22 | jcenter() 23 | google() 24 | } 25 | 26 | dependencies { 27 | api project(':library') 28 | } 29 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':library', ':sample' 2 | --------------------------------------------------------------------------------