11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 AndroidMad
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 | # UpdateHandler
2 | Update Checker For Google Play
3 |
4 |
5 |
6 | ### Featured In
7 | [](https://android-arsenal.com/details/1/3777)
8 |
9 | ### Created By
10 | [](https://androidmads.blogspot.in/2016/06/automatic-update-checker-for-android.html)
11 |
12 | ### How to Import the Library:
13 | [](https://bintray.com/androidmads/maven/androidmads.updatehandler/1.0.3/link)
14 |
15 | Gradle:
16 | ```groovy
17 | compile 'androidmads.updatehandler:updatehandler:1.0.5'
18 | ```
19 |
20 | Maven:
21 | ```groovy
22 |
23 | androidmads.updatehandler
24 | updatehandler
25 | 1.0.5
26 | pom
27 |
28 | ```
29 | ### How to use this Library:
30 |
31 | After importing this library, use the following lines to check version update for your application automatically.
32 | ```java
33 | /**
34 | * This library works in release mode only with the same JKS key used for
35 | * your Previous Version
36 | */
37 | new UpdateHandler.Builder(this)
38 | .setContent("New Version Found")
39 | .setTitle("Update Found")
40 | .setUpdateText("Yes")
41 | .setCancelText("No")
42 | .showDefaultAlert(true)
43 | .showWhatsNew(true)
44 | .setCheckerCount(2)
45 | .setOnUpdateFoundLister(new UpdateHandler.Builder.UpdateListener() {
46 | @Override
47 | public void onUpdateFound(boolean newVersion, String whatsNew) {
48 | tv.setText(tv.getText() + "\n\nUpdate Found : " + newVersion + "\n\nWhat's New\n" + whatsNew);
49 | }
50 | })
51 | .setOnUpdateClickLister(new UpdateHandler.Builder.UpdateClickListener() {
52 | @Override
53 | public void onUpdateClick(boolean newVersion, String whatsNew) {
54 | Log.v("onUpdateClick", String.valueOf(newVersion));
55 | Log.v("onUpdateClick", whatsNew);
56 | }
57 | })
58 | .setOnCancelClickLister(new UpdateHandler.Builder.UpdateCancelListener() {
59 | @Override
60 | public void onCancelClick() {
61 | Log.v("onCancelClick", "Cancelled");
62 | }
63 | })
64 | .build();
65 | ```
66 | # Demo:
67 |
68 |
69 |
70 |
71 |
72 |
Alert Without What' New
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
Alert With What' New
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
Update Prompt with Custom Listener
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 | #License:
97 |
The MIT License (MIT)
98 |
99 | Copyright (c) 2017 AndroidMad
100 |
101 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
102 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation
103 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
104 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
105 |
106 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
107 |
108 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
109 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
110 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
111 | CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
112 | IN THE SOFTWARE.
113 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/app-release.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidmads/UpdateHandler/314d2bb482385878a63f8be7d6f0056e6a9d5ea4/app/app-release.apk
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion '25.0.2'
6 |
7 | defaultConfig {
8 | applicationId "com.ajts.sab_2"
9 | minSdkVersion 15
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | multiDexEnabled true
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(include: ['*.jar'], dir: 'libs')
26 | testCompile 'junit:junit:4.12'
27 | compile 'com.android.support:appcompat-v7:25.2.0'
28 | // compile project(':updatehandler')
29 | compile 'androidmads.updatehandler:updatehandler:1.0.5'
30 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in F:\Dev_Tools\Android_Studio\sdk\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
29 |
30 |
31 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ajts/sab_2/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.ajts.sab_2;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 | import android.widget.TextView;
7 |
8 | import androidmads.updatehandler.app.UpdateHandler;
9 |
10 | public class MainActivity extends AppCompatActivity {
11 |
12 | TextView tv;
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_main);
18 |
19 | tv = (TextView) findViewById(R.id.uhlPrompt);
20 |
21 | new UpdateHandler.Builder(this)
22 | .setTitle("Update Found")
23 | .setContent("New Version Found")
24 | .setUpdateText("Yes")
25 | .setCancelText("No")
26 | .showDefaultAlert(true)
27 | .showWhatsNew(false)
28 | .setCheckerCount(2)
29 | .setOnUpdateFoundLister(new UpdateHandler.Builder.UpdateListener() {
30 | @Override
31 | public void onUpdateFound(boolean newVersion, String whatsNew) {
32 | tv.setText(tv.getText() + "\n\nUpdate Found : " + newVersion + "\n\nWhat's New\n" + whatsNew);
33 | }
34 | })
35 | .setOnUpdateClickLister(new UpdateHandler.Builder.UpdateClickListener() {
36 | @Override
37 | public void onUpdateClick(boolean newVersion, String whatsNew) {
38 | Log.v("onUpdateClick", String.valueOf(newVersion));
39 | Log.v("onUpdateClick", whatsNew);
40 | }
41 | })
42 | .setOnCancelClickLister(new UpdateHandler.Builder.UpdateCancelListener() {
43 | @Override
44 | public void onCancelClick() {
45 | Log.v("onCancelClick", "Cancelled");
46 | }
47 | })
48 | .build();
49 |
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidmads/UpdateHandler/314d2bb482385878a63f8be7d6f0056e6a9d5ea4/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidmads/UpdateHandler/314d2bb482385878a63f8be7d6f0056e6a9d5ea4/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidmads/UpdateHandler/314d2bb482385878a63f8be7d6f0056e6a9d5ea4/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidmads/UpdateHandler/314d2bb482385878a63f8be7d6f0056e6a9d5ea4/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidmads/UpdateHandler/314d2bb482385878a63f8be7d6f0056e6a9d5ea4/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | UHL Sample
3 | Update Handler Library Sample
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/mybackupscheme.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.1'
9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidmads/UpdateHandler/314d2bb482385878a63f8be7d6f0056e6a9d5ea4/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Mar 08 21:35:56 IST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':updatehandler'
2 |
--------------------------------------------------------------------------------
/updatehandler/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/updatehandler/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.jfrog.bintray'
3 | apply plugin: 'com.github.dcendents.android-maven'
4 |
5 | group = 'androidmads.updatehandler' // Change this to match your package name
6 | version = '1.0.5' // Change this to match your version number
7 |
8 | android {
9 | compileSdkVersion 25
10 | buildToolsVersion '25.0.2'
11 |
12 | defaultConfig {
13 | minSdkVersion 15
14 | }
15 | buildTypes {
16 |
17 | }
18 | }
19 |
20 | dependencies {
21 | compile fileTree(include: ['*.jar'], dir: 'libs')
22 | compile 'org.jsoup:jsoup:1.10.1'
23 | compile 'com.android.support:appcompat-v7:25.2.0'
24 | }
25 |
26 | def siteUrl = 'https://github.com/androidmads/UpdateHandler' // Homepage URL of the library
27 | def gitUrl = 'https://github.com/androidmads/UpdateHandler.git' // Git URL
28 |
29 | install {
30 | repositories.mavenInstaller {
31 | // This generates POM.xml with proper parameters
32 | pom {
33 | project {
34 | packaging 'aar'
35 |
36 | // Add your description here
37 | name ''
38 | url siteUrl
39 |
40 | // Set your license
41 | licenses {
42 | license {
43 | name 'The Apache Software License, Version 2.0'
44 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
45 | }
46 | }
47 | developers {
48 | developer {
49 | id 'androidmads'
50 | name 'mushtaq'
51 | email 'mushtaqat3gb@gmail.com'
52 | }
53 | }
54 | scm {
55 | connection gitUrl
56 | developerConnection gitUrl
57 | url siteUrl
58 | }
59 | }
60 | }
61 | }
62 | }
63 |
64 | Properties properties = new Properties()
65 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
66 |
67 | bintray {
68 | user = properties.getProperty("bintray.user")
69 | key = properties.getProperty("bintray.apikey")
70 | configurations = ['archives']
71 | pkg {
72 | repo = 'maven'
73 | name = group
74 |
75 | version {
76 | name = '1.0.5'
77 | desc = 'Update Checker Library'
78 | released = new Date()
79 | vcsTag = '1.0.5'
80 | }
81 |
82 | licenses = ['Apache-2.0']
83 | vcsUrl = gitUrl
84 | websiteUrl = siteUrl
85 | }
86 | }
87 |
88 | task generateSourcesJar(type: Jar) {
89 | from android.sourceSets.main.java.srcDirs
90 | classifier 'sources'
91 | }
92 |
93 | task generateJavadocs(type: Javadoc) {
94 | source = android.sourceSets.main.java.srcDirs
95 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
96 | }
97 |
98 | task generateJavadocsJar(type: Jar) {
99 | from generateJavadocs.destinationDir
100 | classifier 'javadoc'
101 | }
102 |
103 | artifacts {
104 | archives generateSourcesJar
105 | archives generateJavadocsJar
106 | }
107 |
--------------------------------------------------------------------------------
/updatehandler/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in F:\Dev_Tools\Android_Studio\sdk\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/updatehandler/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/updatehandler/src/main/java/androidmads/updatehandler/app/UpdateHandler.java:
--------------------------------------------------------------------------------
1 | package androidmads.updatehandler.app;
2 |
3 | import android.content.Context;
4 | import android.net.ConnectivityManager;
5 | import android.net.NetworkInfo;
6 | import android.os.AsyncTask;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.util.Log;
9 |
10 | import org.jsoup.Jsoup;
11 |
12 | import java.net.HttpURLConnection;
13 | import java.net.URL;
14 | import java.util.concurrent.ExecutionException;
15 |
16 | import androidmads.updatehandler.app.helper.Alert;
17 | import androidmads.updatehandler.app.manager.PrefManager;
18 |
19 | public class UpdateHandler {
20 |
21 | private AppCompatActivity activity;
22 | private Alert alert;
23 | private PrefManager prefManager;
24 | private Builder builder;
25 |
26 | private UpdateHandler(AppCompatActivity activity, Builder builder) {
27 | this.activity = activity;
28 | this.alert = new Alert(activity);
29 | this.prefManager = new PrefManager(activity);
30 | this.builder = builder;
31 | start();
32 | }
33 |
34 | public String start = "";
35 |
36 | private void start() {
37 | try {
38 | if (prefManager.getCount() == 0) {
39 | if (!isNetworkAvailable()) {
40 | if (builder.updateListener != null)
41 | builder.updateListener.onUpdateFound(false, "No Internet Connection");
42 | }
43 | if (IsNewVersionAvailable(activity)) {
44 | start = whatNew(activity.getPackageName());
45 | builder.updateListener.onUpdateFound(true, start);
46 | if (!builder.showAlert)
47 | return;
48 | alert.showDialog(builder,
49 | start,
50 | getMarketVersion(activity));
51 | } else {
52 | builder.updateListener.onUpdateFound(false, "No Update");
53 | }
54 | }
55 | prefManager.setCount();
56 | } catch (Exception e) {
57 | builder.updateListener.onUpdateFound(false, e.getMessage());
58 | }
59 | }
60 |
61 | // Check Version Availability
62 |
63 | private boolean IsNewVersionAvailable(AppCompatActivity appCompatActivity) {
64 | try {
65 | if (isNetworkAvailable()) {
66 | CheckUrlExists checkUrlExists = new CheckUrlExists(appCompatActivity);
67 | boolean result = checkUrlExists.execute().get();
68 | if (result) {
69 | String AppVersion = getInstalledAppVersion(appCompatActivity);
70 | String MarketVersion = getMarketVersion(appCompatActivity);
71 | return versionCompare(MarketVersion, AppVersion);
72 | }
73 | }
74 | } catch (Exception ignored) {
75 | }
76 | return false;
77 | }
78 |
79 | private boolean versionCompare(String NewVersion, String OldVersion) {
80 | String[] vals1 = NewVersion.split("\\.");
81 | String[] vals2 = OldVersion.split("\\.");
82 | int i = 0;
83 | // set index to first non-equal ordinal or length of shortest version string
84 | while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) {
85 | i++;
86 | }
87 | // compare first non-equal ordinal number
88 | if (i < vals1.length && i < vals2.length) {
89 | int diff = Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i]));
90 | return Integer.signum(diff) > 0;
91 | }
92 | // the strings are equal or one string is a substring of the other
93 | // e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4"
94 | return Integer.signum(vals1.length - vals2.length) > 0;
95 | }
96 |
97 | private String getMarketVersion(AppCompatActivity appCompatActivity) {
98 | try {
99 | return new MarketInfo(appCompatActivity.getPackageName(), "softwareVersion").execute().get();
100 | } catch (InterruptedException | ExecutionException e) {
101 | e.printStackTrace();
102 | }
103 |
104 | return "";
105 | }
106 |
107 | private String getInstalledAppVersion(AppCompatActivity appCompatActivity) {
108 | try {
109 | return new AppInfo(appCompatActivity).execute().get();
110 | } catch (InterruptedException | ExecutionException e) {
111 | e.printStackTrace();
112 | }
113 | return "";
114 | }
115 |
116 | private String whatNew(String packageName) {
117 | String whatsNew = null;
118 | try {
119 | whatsNew = new whatsNew(packageName, "div[class=recent-change]").execute().get();
120 | whatsNew = whatsNew.replaceAll("[\r\n]+", "\n-");
121 | whatsNew = whatsNew.substring(0, whatsNew.length());
122 | } catch (InterruptedException | ExecutionException e) {
123 | e.printStackTrace();
124 | }
125 | return whatsNew;
126 | }
127 |
128 | // Check Url Existence
129 | private class CheckUrlExists extends AsyncTask {
130 |
131 | AppCompatActivity appCompatActivity;
132 | boolean IsUrlExist = false;
133 |
134 | CheckUrlExists(AppCompatActivity compatActivity) {
135 | appCompatActivity = compatActivity;
136 | }
137 |
138 | @Override
139 | protected Boolean doInBackground(Void... voids) {
140 | try {
141 | URL url = new URL("https://play.google.com/store/apps/details?id=" + appCompatActivity.getPackageName());
142 | HttpURLConnection huc = (HttpURLConnection) url.openConnection();
143 | huc.setRequestMethod("GET");
144 | huc.connect();
145 | IsUrlExist = isNetworkAvailable() && huc.getResponseCode() == 200;
146 | } catch (Exception e) {
147 | IsUrlExist = false;
148 | }
149 | return IsUrlExist;
150 | }
151 | }
152 |
153 | // Check App's Market Version Details
154 | private class MarketInfo extends AsyncTask {
155 | String MarketVersion = "";
156 | String PackageName = "";
157 | String ItemType = "";
158 |
159 | MarketInfo(String PackageName, String ItemType) {
160 | this.PackageName = PackageName;
161 | this.ItemType = ItemType;
162 | }
163 |
164 | @Override
165 | protected String doInBackground(Void... voids) {
166 | try {
167 | return Jsoup.connect("https://play.google.com/store/apps/details?id=" + PackageName)
168 | .timeout(60000)
169 | .ignoreHttpErrors(true)
170 | .referrer("http://www.google.com")
171 | .get()
172 | .select("div[itemprop=" + ItemType + "]")
173 | .first() // .recent-change
174 | .ownText();
175 | } catch (Exception ignored) {
176 |
177 | }
178 | return MarketVersion;
179 | }
180 | }
181 |
182 | // Check App's Version Details
183 | private class AppInfo extends AsyncTask {
184 | String AppVersion = "";
185 | AppCompatActivity appCompatActivity;
186 |
187 | AppInfo(AppCompatActivity compatActivity) {
188 | appCompatActivity = compatActivity;
189 | }
190 |
191 | @Override
192 | protected String doInBackground(Void... voids) {
193 | try {
194 | return AppVersion = appCompatActivity.getPackageManager().getPackageInfo(appCompatActivity.getPackageName(), 0).versionName + "";
195 | } catch (Exception ignored) {
196 |
197 | }
198 | return AppVersion;
199 | }
200 |
201 | }
202 |
203 | // Check for What's New
204 | private class whatsNew extends AsyncTask {
205 | String PackageName = "";
206 | String ItemType = "";
207 |
208 | whatsNew(String PackageName, String ItemType) {
209 | this.PackageName = PackageName;
210 | this.ItemType = ItemType;
211 | }
212 |
213 | @Override
214 | protected String doInBackground(Void... voids) {
215 | try {
216 | return Jsoup.connect("https://play.google.com/store/apps/details?id=" + PackageName)
217 | .timeout(60000)
218 | .ignoreHttpErrors(true)
219 | .referrer("http://www.google.com")
220 | .get()
221 | .select(ItemType)
222 | .first().ownText();
223 |
224 | } catch (Exception e) {
225 | Log.v("ItemType", e.getMessage() + " 123");
226 | e.printStackTrace();
227 | }
228 | return "";
229 | }
230 | }
231 |
232 | // Check Internet Connection
233 | @SuppressWarnings("deprecation")
234 | private boolean isNetworkAvailable() {
235 | boolean status = false;
236 | try {
237 | ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
238 | NetworkInfo netInfo = cm.getNetworkInfo(0);
239 |
240 | if (netInfo != null
241 | && netInfo.getState() == NetworkInfo.State.CONNECTED) {
242 | status = true;
243 | } else {
244 | netInfo = cm.getNetworkInfo(1);
245 | if (netInfo != null
246 | && netInfo.getState() == NetworkInfo.State.CONNECTED)
247 | status = true;
248 | }
249 | } catch (Exception e) {
250 | e.printStackTrace();
251 | return false;
252 | }
253 | return status;
254 | }
255 |
256 | public static class Builder {
257 |
258 | AppCompatActivity appCompatActivity;
259 | public String title = "Update Found";
260 | public boolean showWhatsNew = false;
261 | public String update = "Update";
262 | public String cancel = "Cancel";
263 | public String updateContent = "New Version ([VERSION]) Available for [APP_NAME]";
264 | public boolean showAlert = true;
265 | public boolean cancelable = true;
266 | public UpdateClickListener updateClickLister = null;
267 | public UpdateCancelListener updateCancelListener = null;
268 | public UpdateListener updateListener = null;
269 | PrefManager prefManager;
270 |
271 | public interface UpdateListener {
272 | void onUpdateFound(boolean newVersion, String whatsNew);
273 | }
274 |
275 | public interface UpdateClickListener {
276 | void onUpdateClick(boolean newVersion, String whatsNew);
277 | }
278 |
279 | public interface UpdateCancelListener {
280 | void onCancelClick();
281 | }
282 |
283 | public Builder(AppCompatActivity appCompatActivity) {
284 | this.appCompatActivity = appCompatActivity;
285 | prefManager = new PrefManager(appCompatActivity);
286 | }
287 |
288 | public Builder setTitle(String title) {
289 | this.title = title;
290 | return this;
291 | }
292 |
293 | public Builder showWhatsNew(boolean showWhatsNew) {
294 | this.showWhatsNew = showWhatsNew;
295 | return this;
296 | }
297 |
298 | public Builder showDefaultAlert(boolean showAlert) {
299 | this.showAlert = showAlert;
300 | return this;
301 | }
302 |
303 | public Builder setUpdateText(String update) {
304 | this.update = update;
305 | return this;
306 | }
307 |
308 | public Builder setCancelText(String cancel) {
309 | this.cancel = cancel;
310 | return this;
311 | }
312 |
313 | public Builder setContent(String updateContent) {
314 | this.updateContent = updateContent;
315 | return this;
316 | }
317 |
318 | public Builder setCheckerCount(int count) {
319 | this.prefManager.setPref(count);
320 | return this;
321 | }
322 |
323 | public Builder setCancelable(boolean cancelable) {
324 | this.cancelable = cancelable;
325 | return this;
326 | }
327 |
328 | public Builder setOnUpdateClickLister(UpdateClickListener updateClickLister) {
329 | this.updateClickLister = updateClickLister;
330 | return this;
331 | }
332 |
333 | public Builder setOnCancelClickLister(UpdateCancelListener updateCancelListener) {
334 | this.updateCancelListener = updateCancelListener;
335 | return this;
336 | }
337 |
338 | public Builder setOnUpdateFoundLister(UpdateListener updateLister) {
339 | this.updateListener = updateLister;
340 | return this;
341 | }
342 |
343 | public UpdateHandler build() {
344 | return new UpdateHandler(appCompatActivity, this);
345 | }
346 | }
347 |
348 | }
349 |
--------------------------------------------------------------------------------
/updatehandler/src/main/java/androidmads/updatehandler/app/helper/Alert.java:
--------------------------------------------------------------------------------
1 | package androidmads.updatehandler.app.helper;
2 |
3 | import android.content.DialogInterface;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.support.v7.app.AlertDialog;
7 | import android.support.v7.app.AppCompatActivity;
8 |
9 | import androidmads.updatehandler.app.UpdateHandler;
10 |
11 | public class Alert {
12 |
13 | private AppCompatActivity activity;
14 |
15 | public Alert(AppCompatActivity activity) {
16 | this.activity = activity;
17 | }
18 |
19 | public void showDialog(final UpdateHandler.Builder builder, final String whatsNew, final String version) {
20 | AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
21 | alertDialogBuilder.setTitle(builder.title);
22 | try {
23 | String appName = activity.getPackageManager().getApplicationLabel(
24 | activity.getPackageManager().getApplicationInfo(
25 | activity.getPackageName(), 0)).toString();
26 | String message = builder.updateContent.replace("[VERSION]", version).replace("[APP_NAME]", appName);
27 | if (builder.showAlert) {
28 | if (builder.showWhatsNew)
29 | message = message + "\n" + whatsNew;
30 | }
31 | alertDialogBuilder.setMessage(message);
32 | alertDialogBuilder.setCancelable(builder.cancelable);
33 | alertDialogBuilder.setPositiveButton(builder.update, new DialogInterface.OnClickListener() {
34 | @Override
35 | public void onClick(DialogInterface dialog, int which) {
36 | if (builder.updateClickLister != null)
37 | builder.updateClickLister.onUpdateClick(true, whatsNew);
38 | else
39 | goToMarket();
40 | }
41 | });
42 | alertDialogBuilder.setNegativeButton(builder.cancel, new DialogInterface.OnClickListener() {
43 | @Override
44 | public void onClick(DialogInterface dialog, int which) {
45 | if (builder.updateCancelListener != null)
46 | builder.updateCancelListener.onCancelClick();
47 | else
48 | dialog.dismiss();
49 | }
50 | });
51 | AlertDialog alertDialog = alertDialogBuilder.create();
52 | alertDialog.show();
53 | } catch (Exception ignored) {
54 | }
55 |
56 | }
57 |
58 | private void goToMarket() {
59 | try {
60 | activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="
61 | + activity.getPackageName())));
62 | } catch (android.content.ActivityNotFoundException anfe) {
63 | activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id="
64 | + activity.getPackageName())));
65 | }
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/updatehandler/src/main/java/androidmads/updatehandler/app/manager/PrefManager.java:
--------------------------------------------------------------------------------
1 | package androidmads.updatehandler.app.manager;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.content.SharedPreferences;
6 | import android.content.SharedPreferences.Editor;
7 |
8 | @SuppressLint("CommitPrefEdits")
9 | public class PrefManager {
10 |
11 | public static final String KEY_COUNT = "count";
12 | public static final String KEY_PREF = "pref";
13 |
14 | private SharedPreferences pref;
15 | private Editor editor;
16 |
17 | public PrefManager(Activity activity) {
18 | int PRIVATE_MODE = 0;
19 | pref = activity.getSharedPreferences(activity.getPackageName(), PRIVATE_MODE);
20 | }
21 |
22 | public void setCount() {
23 | editor = pref.edit();
24 | editor.putInt(KEY_COUNT, getCount() + 1);
25 | editor.apply();
26 | }
27 |
28 | public int getCount() {
29 | if (pref.getInt(KEY_COUNT, 0) >= getPref()) {
30 | editor = pref.edit();
31 | editor.putInt(KEY_COUNT, 0);
32 | editor.apply();
33 | return 0;
34 | } else {
35 | return pref.getInt(KEY_COUNT, 0);
36 | }
37 | }
38 |
39 | public void setPref(int count) {
40 | editor = pref.edit();
41 | editor.putInt(KEY_PREF, count);
42 | editor.apply();
43 | }
44 |
45 | private int getPref() {
46 | return pref.getInt(KEY_PREF, 5);
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/updatehandler/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | UpdateHandler
3 | Update Found
4 |
5 |
--------------------------------------------------------------------------------
/updatehandler/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/w_custom_listener.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidmads/UpdateHandler/314d2bb482385878a63f8be7d6f0056e6a9d5ea4/w_custom_listener.png
--------------------------------------------------------------------------------
/w_o_whatsnew.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidmads/UpdateHandler/314d2bb482385878a63f8be7d6f0056e6a9d5ea4/w_o_whatsnew.png
--------------------------------------------------------------------------------
/w_whatsnew.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidmads/UpdateHandler/314d2bb482385878a63f8be7d6f0056e6a9d5ea4/w_whatsnew.png
--------------------------------------------------------------------------------