├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── eu
│ │ │ └── dkaratzas
│ │ │ └── android
│ │ │ └── inapp
│ │ │ └── update
│ │ │ └── sample
│ │ │ ├── Immediate.java
│ │ │ ├── FlexibleDefaultSnackbar.java
│ │ │ ├── FlexibleWithCustomNotification.java
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── eu
│ │ │ └── dkaratzas
│ │ │ └── android
│ │ │ └── inapp
│ │ │ └── update
│ │ │ └── sample
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── eu
│ │ └── dkaratzas
│ │ └── android
│ │ └── inapp
│ │ └── update
│ │ └── sample
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── library
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── eu
│ │ │ └── dkaratzas
│ │ │ └── android
│ │ │ └── inapp
│ │ │ └── update
│ │ │ ├── Constants.java
│ │ │ ├── InAppUpdateStatus.java
│ │ │ └── InAppUpdateManager.java
│ ├── test
│ │ └── java
│ │ │ └── eu
│ │ │ └── dkaratzas
│ │ │ └── android
│ │ │ └── inapp
│ │ │ └── update
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── eu
│ │ └── dkaratzas
│ │ └── android
│ │ └── inapp
│ │ └── update
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── docs
└── javadoc
│ ├── package-list
│ ├── script.js
│ ├── allclasses-noframe.html
│ ├── allclasses-frame.html
│ ├── eu
│ └── dkaratzas
│ │ └── android
│ │ └── inapp
│ │ └── update
│ │ ├── package-frame.html
│ │ ├── package-tree.html
│ │ ├── package-summary.html
│ │ ├── InAppUpdateManager.InAppUpdateHandler.html
│ │ ├── Constants.html
│ │ ├── InAppUpdateStatus.html
│ │ └── Constants.UpdateMode.html
│ ├── index.html
│ ├── deprecated-list.html
│ ├── constant-values.html
│ ├── overview-tree.html
│ ├── help-doc.html
│ └── stylesheet.css
├── gradle
├── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
└── bintray.gradle
├── .github
└── ISSUE_TEMPLATE
│ ├── feature_request.md
│ └── bug_report.md
├── .travis.yml
├── gradle.properties
├── .gitignore
├── gradlew.bat
├── gradlew
├── README.md
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------
/docs/javadoc/package-list:
--------------------------------------------------------------------------------
1 | eu.dkaratzas.android.inapp.update
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Sample
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dioKaratzas/android-inapp-update/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Android In-App Update Library
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dioKaratzas/android-inapp-update/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dioKaratzas/android-inapp-update/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dioKaratzas/android-inapp-update/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dioKaratzas/android-inapp-update/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dioKaratzas/android-inapp-update/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dioKaratzas/android-inapp-update/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dioKaratzas/android-inapp-update/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dioKaratzas/android-inapp-update/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dioKaratzas/android-inapp-update/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dioKaratzas/android-inapp-update/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #48B19B
4 | #32323B
5 | #FF6859
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Mar 15 17:51:38 EET 2020
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-6.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/java/eu/dkaratzas/android/inapp/update/Constants.java:
--------------------------------------------------------------------------------
1 | package eu.dkaratzas.android.inapp.update;
2 |
3 | public class Constants {
4 |
5 | public enum UpdateMode {
6 | FLEXIBLE,
7 | IMMEDIATE
8 | }
9 |
10 | public static final int UPDATE_ERROR_START_APP_UPDATE_FLEXIBLE = 100;
11 | public static final int UPDATE_ERROR_START_APP_UPDATE_IMMEDIATE = 101;
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 |
5 | ---
6 |
7 | **Describe the solution you'd like**
8 | A clear and concise description of what you want to happen.
9 |
10 | **Describe alternatives you've considered**
11 | A clear and concise description of any alternative solutions or features you've considered.
12 |
13 | **Additional context**
14 | Add any other context or screenshots about the feature request here.
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/docs/javadoc/script.js:
--------------------------------------------------------------------------------
1 | function show(type)
2 | {
3 | count = 0;
4 | for (var key in methods) {
5 | var row = document.getElementById(key);
6 | if ((methods[key] & type) != 0) {
7 | row.style.display = '';
8 | row.className = (count++ % 2) ? rowColor : altColor;
9 | }
10 | else
11 | row.style.display = 'none';
12 | }
13 | updateTabs(type);
14 | }
15 |
16 | function updateTabs(type)
17 | {
18 | for (var value in tabs) {
19 | var sNode = document.getElementById(tabs[value][0]);
20 | var spanNode = sNode.firstChild;
21 | if (value == type) {
22 | sNode.className = activeTableTab;
23 | spanNode.innerHTML = tabs[value][1];
24 | }
25 | else {
26 | sNode.className = tableTab;
27 | spanNode.innerHTML = "" + tabs[value][1] + " ";
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 |
5 | ---
6 |
7 | **Describe the bug**
8 | A clear and concise description of what the bug is.
9 |
10 | **To Reproduce**
11 | Steps to reproduce the behaviour including how the prompt builder is created:
12 | 1. Go to '...'
13 | 2. Click on '....'
14 | 3. Scroll down to '....'
15 | 4. See error
16 |
17 | **Expected behavior**
18 | A clear and concise description of what you expected to happen.
19 |
20 | **Screenshots**
21 | If applicable, add screenshots to help explain your problem.
22 |
23 | **Stack trace**
24 | If applicable, add the stack trace for the exception thrown to help trace your problem.
25 |
26 | **Smartphone (please complete the following information):**
27 | - Device: [e.g. Google Pixel]
28 | - OS: [e.g. Android 7.1 Nougat API 25]
29 | - Library version [e.g. 1.0.0]
30 |
31 | **Additional context**
32 | Add any other context about the problem here.
33 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | sudo: required
3 | jdk: oraclejdk8
4 |
5 | env:
6 | global:
7 | - ANDROID_API_LEVEL=28
8 | - ANDROID_BUILD_TOOLS_VERSION=28.0.3
9 | - ANDROID_ABI=armeabi-v7a
10 |
11 | android:
12 | components:
13 | - tools
14 | - platform-tools
15 | - tools
16 | - extra-android-m2repository
17 | licenses:
18 | - 'android-sdk-preview-license-52d11cd2'
19 | - 'android-sdk-license-.+'
20 | - 'google-gdk-license-.+'
21 |
22 | before_install:
23 | - touch $HOME/.android/repositories.cfg
24 | - yes | sdkmanager "platforms;android-28"
25 | - yes | sdkmanager "build-tools;28.0.3"
26 |
27 | before_cache:
28 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
29 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/
30 |
31 | cache:
32 | directories:
33 | - $HOME/.gradle/caches/
34 | - $HOME/.gradle/wrapper/
35 | - $HOME/.android/build-cache
36 |
37 | before_script:
38 | - chmod +x gradlew
39 |
40 | script:
41 | - ./gradlew clean build
42 | - ./gradlew test
43 |
44 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/library/src/test/java/eu/dkaratzas/android/inapp/update/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Dionysios Karatzas
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.dkaratzas.android.inapp.update;
18 |
19 | import org.junit.Test;
20 |
21 | import static org.junit.Assert.*;
22 |
23 | /**
24 | * Example local unit test, which will execute on the development machine (host).
25 | *
26 | * @see Testing documentation
27 | */
28 | public class ExampleUnitTest {
29 | @Test
30 | public void addition_isCorrect() {
31 | assertEquals(4, 2 + 2);
32 | }
33 | }
--------------------------------------------------------------------------------
/app/src/test/java/eu/dkaratzas/android/inapp/update/sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Dionysios Karatzas
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.dkaratzas.android.inapp.update.sample;
18 |
19 | import org.junit.Test;
20 |
21 | import static org.junit.Assert.*;
22 |
23 | /**
24 | * Example local unit test, which will execute on the development machine (host).
25 | *
26 | * @see Testing documentation
27 | */
28 | public class ExampleUnitTest {
29 | @Test
30 | public void addition_isCorrect() {
31 | assertEquals(4, 2 + 2);
32 | }
33 | }
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | version = '1.0.5'
4 |
5 | android {
6 | compileSdkVersion 30
7 | buildToolsVersion "30.0.1"
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion 30
12 | versionCode 1
13 | versionName "1.0.0"
14 |
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 |
31 | implementation 'com.google.android.play:core:1.10.0'
32 | implementation 'androidx.annotation:annotation:1.2.0'
33 | implementation 'androidx.lifecycle:lifecycle-runtime:2.3.1'
34 | annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.3.1'
35 | implementation 'com.google.android.material:material:1.3.0'
36 | testImplementation 'junit:junit:4.13'
37 | androidTestImplementation 'androidx.test:runner:1.3.0'
38 | }
39 |
40 | apply from: "${rootDir}/gradle/bintray.gradle"
41 |
42 |
43 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 | *.aab
5 |
6 | # Files for the ART/Dalvik VM
7 | *.dex
8 |
9 | # Java class files
10 | *.class
11 |
12 | # Generated files
13 | bin/
14 | gen/
15 | out/
16 |
17 | # Gradle files
18 | .gradle/
19 | build/
20 |
21 | # Local configuration file (sdk path, etc)
22 | local.properties
23 |
24 | # Proguard folder generated by Eclipse
25 | proguard/
26 |
27 | # Log Files
28 | *.log
29 |
30 | # Android Studio Navigation editor temp files
31 | .navigation/
32 |
33 | # Android Studio captures folder
34 | captures/
35 |
36 | # IntelliJ
37 | *.iml
38 | .idea/*
39 |
40 | # Keystore files
41 | # Uncomment the following lines if you do not want to check your keystore files in.
42 | #*.jks
43 | #*.keystore
44 |
45 | # External native build folder generated in Android Studio 2.2 and later
46 | .externalNativeBuild
47 |
48 | # Google Services (e.g. APIs or Firebase)
49 | # google-services.json
50 |
51 | # Freeline
52 | freeline.py
53 | freeline/
54 | freeline_project_description.json
55 |
56 | # fastlane
57 | fastlane/report.xml
58 | fastlane/Preview.html
59 | fastlane/screenshots
60 | fastlane/test_output
61 | fastlane/readme.md
62 |
63 | # OS-specific files
64 | .DS_Store
65 | .DS_Store?
66 | ._*
67 | .Spotlight-V100
68 | .Trashes
69 | ehthumbs.db
70 | Thumbs.db
71 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 30
5 | buildToolsVersion "30.0.1"
6 | defaultConfig {
7 | applicationId "eu.dkaratzas.android.inapp.update.sample"
8 | minSdkVersion 17
9 | targetSdkVersion 30
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | compileOptions {
21 | sourceCompatibility JavaVersion.VERSION_1_8
22 | targetCompatibility JavaVersion.VERSION_1_8
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation project(':library')
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 | implementation 'androidx.appcompat:appcompat:1.3.0'
30 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
31 | testImplementation 'junit:junit:4.13'
32 | androidTestImplementation 'androidx.test:runner:1.3.0'
33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
34 | implementation 'com.google.android.material:material:1.4.0-rc01'
35 | implementation 'com.jakewharton:butterknife:10.1.0'
36 | annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
37 | }
38 |
--------------------------------------------------------------------------------
/docs/javadoc/allclasses-noframe.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | All Classes (library 1.0.1 API)
7 |
8 |
9 |
10 |
11 |
12 | All Classes
13 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/docs/javadoc/allclasses-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | All Classes (library 1.0.1 API)
7 |
8 |
9 |
10 |
11 |
12 | All Classes
13 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/eu/dkaratzas/android/inapp/update/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Dionysios Karatzas
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.dkaratzas.android.inapp.update;
18 |
19 | import android.content.Context;
20 |
21 | import androidx.test.InstrumentationRegistry;
22 | import androidx.test.runner.AndroidJUnit4;
23 |
24 | import org.junit.Test;
25 | import org.junit.runner.RunWith;
26 |
27 | import static org.junit.Assert.*;
28 |
29 | /**
30 | * Instrumented test, which will execute on an Android device.
31 | *
32 | * @see Testing documentation
33 | */
34 | @RunWith(AndroidJUnit4.class)
35 | public class ExampleInstrumentedTest {
36 | @Test
37 | public void useAppContext() {
38 | // Context of the app under test.
39 | Context appContext = InstrumentationRegistry.getTargetContext();
40 |
41 | assertEquals("eu.dkaratzas.android.inapp.update.test", appContext.getPackageName());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/eu/dkaratzas/android/inapp/update/sample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Dionysios Karatzas
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.dkaratzas.android.inapp.update.sample;
18 |
19 | import android.content.Context;
20 |
21 | import androidx.test.InstrumentationRegistry;
22 | import androidx.test.runner.AndroidJUnit4;
23 |
24 | import org.junit.Test;
25 | import org.junit.runner.RunWith;
26 |
27 | import static org.junit.Assert.*;
28 |
29 | /**
30 | * Instrumented test, which will execute on an Android device.
31 | *
32 | * @see Testing documentation
33 | */
34 | @RunWith(AndroidJUnit4.class)
35 | public class ExampleInstrumentedTest {
36 | @Test
37 | public void useAppContext() {
38 | // Context of the app under test.
39 | Context appContext = InstrumentationRegistry.getTargetContext();
40 |
41 | assertEquals("eu.dkaratzas.android.inapp.update.sample", appContext.getPackageName());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/docs/javadoc/eu/dkaratzas/android/inapp/update/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | eu.dkaratzas.android.inapp.update (library 1.0.1 API)
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
Interfaces
15 |
18 |
Classes
19 |
24 |
Enums
25 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/library/src/main/java/eu/dkaratzas/android/inapp/update/InAppUpdateStatus.java:
--------------------------------------------------------------------------------
1 | package eu.dkaratzas.android.inapp.update;
2 |
3 | import com.google.android.play.core.appupdate.AppUpdateInfo;
4 | import com.google.android.play.core.install.InstallState;
5 | import com.google.android.play.core.install.model.InstallStatus;
6 | import com.google.android.play.core.install.model.UpdateAvailability;
7 |
8 | /**
9 | * This class is just a wrapper for AppUpdateInfo and InstallState
10 | * Used by InAppUpdateManager
11 | */
12 | public class InAppUpdateStatus {
13 |
14 | private static final int NO_UPDATE = 0;
15 | private AppUpdateInfo appUpdateInfo;
16 | private InstallState installState;
17 |
18 | public InAppUpdateStatus() {
19 | }
20 |
21 | public void setAppUpdateInfo(AppUpdateInfo appUpdateInfo) {
22 | this.appUpdateInfo = appUpdateInfo;
23 | }
24 |
25 | public void setInstallState(InstallState installState) {
26 | this.installState = installState;
27 | }
28 |
29 | public boolean isDownloading() {
30 | if (installState != null)
31 | return installState.installStatus() == InstallStatus.DOWNLOADING;
32 |
33 | return false;
34 | }
35 |
36 | public boolean isDownloaded() {
37 | if (installState != null)
38 | return installState.installStatus() == InstallStatus.DOWNLOADED;
39 |
40 | return false;
41 | }
42 |
43 | public boolean isFailed() {
44 | if (installState != null)
45 | return installState.installStatus() == InstallStatus.FAILED;
46 |
47 | return false;
48 | }
49 |
50 | public boolean isUpdateAvailable() {
51 | if (appUpdateInfo != null)
52 | return appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE;
53 |
54 | return false;
55 | }
56 |
57 | public int availableVersionCode() {
58 | if (appUpdateInfo != null)
59 | return appUpdateInfo.availableVersionCode();
60 |
61 | return NO_UPDATE;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/eu/dkaratzas/android/inapp/update/sample/Immediate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Dionysios Karatzas
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.dkaratzas.android.inapp.update.sample;
18 |
19 | import android.app.Activity;
20 | import android.content.Intent;
21 | import android.os.Bundle;
22 | import android.util.Log;
23 |
24 | import androidx.annotation.Nullable;
25 | import androidx.appcompat.app.AppCompatActivity;
26 |
27 | import eu.dkaratzas.android.inapp.update.InAppUpdateManager;
28 |
29 | import static eu.dkaratzas.android.inapp.update.Constants.UpdateMode;
30 |
31 | public class Immediate extends AppCompatActivity {
32 | private static final int REQ_CODE_VERSION_UPDATE = 530;
33 | private static final String TAG = "Sample";
34 | private InAppUpdateManager inAppUpdateManager;
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 | setContentView(R.layout.activity_main);
40 |
41 | inAppUpdateManager = InAppUpdateManager.Builder(this, REQ_CODE_VERSION_UPDATE)
42 | .resumeUpdates(true) // Resume the update, if the update was stalled. Default is true
43 | .mode(UpdateMode.IMMEDIATE);
44 |
45 | inAppUpdateManager.checkForAppUpdate();
46 | }
47 |
48 | @Override
49 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
50 | if (requestCode == REQ_CODE_VERSION_UPDATE) {
51 | if (resultCode == Activity.RESULT_CANCELED) {
52 | // If the update is cancelled by the user,
53 | // you can request to start the update again.
54 | inAppUpdateManager.checkForAppUpdate();
55 |
56 | Log.d(TAG, "Update flow failed! Result code: " + resultCode);
57 | }
58 | }
59 |
60 | super.onActivityResult(requestCode, resultCode, data);
61 |
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/docs/javadoc/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | library 1.0.1 API
7 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | JavaScript is disabled on your browser.
67 |
68 | Frame Alert
69 | This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version .
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/app/src/main/java/eu/dkaratzas/android/inapp/update/sample/FlexibleDefaultSnackbar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Dionysios Karatzas
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.dkaratzas.android.inapp.update.sample;
18 |
19 | import android.content.Intent;
20 | import android.os.Bundle;
21 | import android.util.Log;
22 |
23 | import androidx.annotation.Nullable;
24 | import androidx.appcompat.app.AppCompatActivity;
25 |
26 | import eu.dkaratzas.android.inapp.update.InAppUpdateManager;
27 | import eu.dkaratzas.android.inapp.update.InAppUpdateStatus;
28 |
29 | import static eu.dkaratzas.android.inapp.update.Constants.UpdateMode;
30 |
31 | public class FlexibleDefaultSnackbar extends AppCompatActivity implements InAppUpdateManager.InAppUpdateHandler {
32 | private static final int REQ_CODE_VERSION_UPDATE = 530;
33 | private static final String TAG = "Sample";
34 |
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | setContentView(R.layout.activity_main);
39 |
40 | InAppUpdateManager inAppUpdateManager = InAppUpdateManager.Builder(this, REQ_CODE_VERSION_UPDATE)
41 | .resumeUpdates(true) // Resume the update, if the update was stalled. Default is true
42 | .mode(UpdateMode.FLEXIBLE)
43 | .useCustomNotification(false) //default is false
44 | .snackBarMessage("An update has just been downloaded.")
45 | .snackBarAction("RESTART")
46 | .handler(this);
47 |
48 | inAppUpdateManager.checkForAppUpdate();
49 | }
50 |
51 | @Override
52 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
53 | if (requestCode == REQ_CODE_VERSION_UPDATE) {
54 | if (resultCode != RESULT_OK) {
55 | // If the update is cancelled or fails,
56 | // you can request to start the update again.
57 | Log.d(TAG, "Update flow failed! Result code: " + resultCode);
58 | }
59 | }
60 |
61 | super.onActivityResult(requestCode, resultCode, data);
62 |
63 | }
64 |
65 | // InAppUpdateHandler implementation
66 |
67 | @Override
68 | public void onInAppUpdateError(int code, Throwable error) {
69 | /*
70 | * Called when some error occurred. See Constants class for more details
71 | */
72 | Log.d(TAG, "code: " + code, error);
73 | }
74 |
75 | @Override
76 | public void onInAppUpdateStatus(InAppUpdateStatus status) {
77 | /*
78 | * Called when the update status change occurred. See Constants class for more details
79 | */
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/gradle/bintray.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.github.dcendents.android-maven'
2 | apply plugin: 'com.jfrog.bintray'
3 |
4 | ext {
5 | bintrayRepo = 'maven'
6 | bintrayName = 'android-inapp-update'
7 |
8 | libraryName = 'library'
9 | publishedGroupId = 'eu.dkaratzas'
10 | artifact = 'android-inapp-update'
11 |
12 | libraryDescription = 'An implementation of Android In-app Update'
13 |
14 | siteUrl = 'https://github.com/dnKaratzas/android-inapp-update'
15 | gitUrl = 'https://github.com/dnKaratzas/android-inapp-update.git'
16 |
17 | libraryVersion = version
18 |
19 | developerId = 'dkaratzas'
20 | developerName = 'Dionysios Karatzas'
21 | developerEmail = 'dnkaratzas@gmail.com'
22 |
23 | licenseName = 'The Apache Software License, Version 2.0'
24 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
25 | allLicenses = ["Apache-2.0"]
26 | }
27 |
28 | group = publishedGroupId
29 | version = libraryVersion
30 |
31 | install {
32 | group = 'publishing'
33 | repositories.mavenInstaller {
34 | pom.project {
35 | packaging 'aar'
36 | groupId publishedGroupId
37 | artifactId artifact
38 |
39 | name libraryName
40 | description libraryDescription
41 | url siteUrl
42 |
43 | licenses {
44 | license {
45 | name licenseName
46 | url licenseUrl
47 | }
48 | }
49 | developers {
50 | developer {
51 | id developerId
52 | name developerName
53 | email developerEmail
54 | }
55 | }
56 | scm {
57 | connection gitUrl
58 | developerConnection gitUrl
59 | url siteUrl
60 | }
61 | }
62 | }
63 | }
64 |
65 | task sourcesJar(type: Jar) {
66 | classifier = 'sources'
67 | from android.sourceSets.main.java.srcDirs
68 | }
69 |
70 | task javadoc(type: Javadoc) {
71 | group = 'publishing'
72 | failOnError false
73 | source = android.sourceSets.main.java.sourceFiles
74 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
75 | classpath += configurations.compile
76 | destinationDir = file("${rootDir}/docs/javadoc")
77 | }
78 |
79 | task javadocJar(type: Jar, dependsOn: javadoc) {
80 | classifier = 'javadoc'
81 | from javadoc.destinationDir
82 | }
83 |
84 | artifacts {
85 | archives javadocJar
86 | archives sourcesJar
87 | }
88 |
89 | Properties properties = new Properties()
90 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
91 |
92 | bintray {
93 | user = properties.getProperty("bintray.user")
94 | key = properties.getProperty("bintray.apikey")
95 |
96 | configurations = ['archives']
97 | pkg {
98 | repo = bintrayRepo
99 | name = bintrayName
100 | desc = libraryDescription
101 | websiteUrl = siteUrl
102 | vcsUrl = gitUrl
103 | licenses = allLicenses
104 | dryRun = false
105 | publish = true
106 | override = false
107 | publicDownloadNumbers = true
108 | version {
109 | desc = libraryDescription
110 | }
111 | }
112 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
19 |
20 |
29 |
30 |
40 |
41 |
49 |
50 |
56 |
57 |
58 |
59 |
68 |
69 |
81 |
82 |
--------------------------------------------------------------------------------
/app/src/main/java/eu/dkaratzas/android/inapp/update/sample/FlexibleWithCustomNotification.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Dionysios Karatzas
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.dkaratzas.android.inapp.update.sample;
18 |
19 | import android.content.Intent;
20 | import android.os.Bundle;
21 | import android.util.Log;
22 |
23 | import androidx.annotation.Nullable;
24 | import androidx.appcompat.app.AlertDialog;
25 | import androidx.appcompat.app.AppCompatActivity;
26 |
27 | import eu.dkaratzas.android.inapp.update.InAppUpdateManager;
28 | import eu.dkaratzas.android.inapp.update.InAppUpdateStatus;
29 |
30 | import static eu.dkaratzas.android.inapp.update.Constants.UpdateMode;
31 |
32 | public class FlexibleWithCustomNotification extends AppCompatActivity implements InAppUpdateManager.InAppUpdateHandler {
33 | private static final int REQ_CODE_VERSION_UPDATE = 530;
34 | private static final String TAG = "Sample";
35 | private InAppUpdateManager inAppUpdateManager;
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_main);
41 |
42 | inAppUpdateManager = InAppUpdateManager.Builder(this, REQ_CODE_VERSION_UPDATE)
43 | .resumeUpdates(true) // Resume the update, if the update was stalled. Default is true
44 | .mode(UpdateMode.FLEXIBLE)
45 | // default is false. If is set to true you,
46 | // have to manage the user confirmation when
47 | // you detect the InstallStatus.DOWNLOADED status,
48 | .useCustomNotification(true)
49 | .handler(this);
50 |
51 | inAppUpdateManager.checkForAppUpdate();
52 | }
53 |
54 | @Override
55 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
56 | if (requestCode == REQ_CODE_VERSION_UPDATE) {
57 | if (resultCode != RESULT_OK) {
58 | // If the update is cancelled or fails,
59 | // you can request to start the update again.
60 | inAppUpdateManager.checkForAppUpdate();
61 |
62 | Log.d(TAG, "Update flow failed! Result code: " + resultCode);
63 | }
64 | }
65 |
66 | super.onActivityResult(requestCode, resultCode, data);
67 |
68 | }
69 |
70 | // InAppUpdateHandler implementation
71 |
72 | @Override
73 | public void onInAppUpdateError(int code, Throwable error) {
74 | /*
75 | * Called when some error occurred. See Constants class for more details
76 | */
77 | Log.d(TAG, "code: " + code, error);
78 | }
79 |
80 | @Override
81 | public void onInAppUpdateStatus(InAppUpdateStatus status) {
82 | /*
83 | * If the update downloaded, ask user confirmation and complete the update
84 | */
85 |
86 | if (status.isDownloaded()) {
87 |
88 | new AlertDialog.Builder(this)
89 | .setTitle("InAppUpdate")
90 | .setMessage("An update has just been downloaded.")
91 | .setPositiveButton("Complete", (dialog, which) -> {
92 | // Triggers the completion of the update of the app for the flexible flow.
93 | inAppUpdateManager.completeUpdate();
94 | })
95 | .setNegativeButton("Cancel", null)
96 | .show();
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/docs/javadoc/deprecated-list.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Deprecated List (library 1.0.1 API)
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
42 |
69 |
70 |
74 |
75 |
91 |
118 |
119 |
120 |
121 |
--------------------------------------------------------------------------------
/app/src/main/java/eu/dkaratzas/android/inapp/update/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Dionysios Karatzas
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.dkaratzas.android.inapp.update.sample;
18 |
19 | import android.app.Activity;
20 | import android.content.Intent;
21 | import android.os.Bundle;
22 | import android.util.Log;
23 | import android.view.View;
24 | import android.widget.Button;
25 | import android.widget.ProgressBar;
26 | import android.widget.TextView;
27 |
28 | import androidx.annotation.Nullable;
29 | import androidx.appcompat.app.AppCompatActivity;
30 |
31 | import com.google.android.material.button.MaterialButtonToggleGroup;
32 |
33 | import butterknife.BindView;
34 | import butterknife.ButterKnife;
35 | import eu.dkaratzas.android.inapp.update.InAppUpdateManager;
36 | import eu.dkaratzas.android.inapp.update.InAppUpdateStatus;
37 |
38 | import static eu.dkaratzas.android.inapp.update.Constants.UpdateMode;
39 |
40 | public class MainActivity extends AppCompatActivity implements InAppUpdateManager.InAppUpdateHandler {
41 | private static final int REQ_CODE_VERSION_UPDATE = 530;
42 | private static final String TAG = "MainActivity";
43 | private InAppUpdateManager inAppUpdateManager;
44 |
45 | @BindView(R.id.toggle_button_group)
46 | protected MaterialButtonToggleGroup toggleGroup;
47 | @BindView(R.id.bt_update)
48 | protected Button updateButton;
49 | @BindView(R.id.progressBar)
50 | protected ProgressBar progressBar;
51 | @BindView(R.id.tv_available_version)
52 | protected TextView tvVersionCode;
53 | @BindView(R.id.tv_update_available)
54 | protected TextView tvUpdateAvailable;
55 |
56 | @Override
57 | protected void onCreate(Bundle savedInstanceState) {
58 | super.onCreate(savedInstanceState);
59 | setContentView(R.layout.activity_main);
60 | ButterKnife.bind(this);
61 |
62 | inAppUpdateManager = InAppUpdateManager.Builder(this, REQ_CODE_VERSION_UPDATE)
63 | .resumeUpdates(true)
64 | .handler(this);
65 |
66 | toggleGroup.addOnButtonCheckedListener((group, checkedId, isChecked) -> {
67 | if (checkedId == R.id.tb_immediate && isChecked) {
68 | inAppUpdateManager.mode(UpdateMode.IMMEDIATE);
69 | } else {
70 | inAppUpdateManager
71 | .mode(UpdateMode.FLEXIBLE)
72 | .useCustomNotification(true);
73 | }
74 | });
75 |
76 | updateButton.setOnClickListener(view -> inAppUpdateManager.checkForAppUpdate());
77 |
78 | }
79 |
80 |
81 | @Override
82 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
83 | if (requestCode == REQ_CODE_VERSION_UPDATE) {
84 | if (resultCode == Activity.RESULT_CANCELED) {
85 | // If the update is cancelled by the user,
86 | // you can request to start the update again.
87 | inAppUpdateManager.checkForAppUpdate();
88 |
89 | Log.d(TAG, "Update flow failed! Result code: " + resultCode);
90 | }
91 | }
92 |
93 | super.onActivityResult(requestCode, resultCode, data);
94 | }
95 |
96 | // InAppUpdateHandler implementation
97 |
98 | @Override
99 | public void onInAppUpdateError(int code, Throwable error) {
100 | /*
101 | * Called when some error occurred. See Constants class for more details
102 | */
103 | Log.d(TAG, "code: " + code, error);
104 | }
105 |
106 | @Override
107 | public void onInAppUpdateStatus(InAppUpdateStatus status) {
108 |
109 | /*
110 | * Called when the update status change occurred.
111 | */
112 |
113 | progressBar.setVisibility(status.isDownloading() ? View.VISIBLE : View.GONE);
114 |
115 | tvVersionCode.setText(String.format("Available version code: %d", status.availableVersionCode()));
116 | tvUpdateAvailable.setText(String.format("Update available: %s", String.valueOf(status.isUpdateAvailable())));
117 |
118 | if (status.isDownloaded()) {
119 | updateButton.setText("Complete Update");
120 | updateButton.setOnClickListener(view -> inAppUpdateManager.completeUpdate());
121 | }
122 | }
123 |
124 | }
125 |
--------------------------------------------------------------------------------
/docs/javadoc/constant-values.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Constant Field Values (library 1.0.1 API)
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
42 |
69 |
70 |
77 |
110 |
111 |
127 |
128 |
129 | Prev
130 | Next
131 |
132 |
136 |
139 |
140 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
--------------------------------------------------------------------------------
/docs/javadoc/overview-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Class Hierarchy (library 1.0.1 API)
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
42 |
69 |
70 |
77 |
78 |
Class Hierarchy
79 |
80 | java.lang.Object
81 |
86 |
87 |
88 |
Interface Hierarchy
89 |
92 |
Enum Hierarchy
93 |
94 | java.lang.Object
95 |
96 | java.lang.Enum<E> (implements java.lang.Comparable<T>, java.io.Serializable)
97 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
122 |
123 |
124 | Prev
125 | Next
126 |
127 |
131 |
134 |
135 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/docs/javadoc/eu/dkaratzas/android/inapp/update/package-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | eu.dkaratzas.android.inapp.update Class Hierarchy (library 1.0.1 API)
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
42 |
69 |
70 |
73 |
74 |
Class Hierarchy
75 |
76 | java.lang.Object
77 |
82 |
83 |
84 |
Interface Hierarchy
85 |
88 |
Enum Hierarchy
89 |
90 | java.lang.Object
91 |
92 | java.lang.Enum<E> (implements java.lang.Comparable<T>, java.io.Serializable)
93 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
118 |
119 |
120 | Prev
121 | Next
122 |
123 |
127 |
130 |
131 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/docs/javadoc/eu/dkaratzas/android/inapp/update/package-summary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | eu.dkaratzas.android.inapp.update (library 1.0.1 API)
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
42 |
43 |
44 | Prev Package
45 | Next Package
46 |
47 |
51 |
54 |
55 |
65 |
66 |
67 |
68 |
69 |
70 |
73 |
74 |
75 |
76 |
77 | Interface Summary
78 |
79 | Interface
80 | Description
81 |
82 |
83 |
84 | InAppUpdateManager.InAppUpdateHandler
85 |
86 | Callback methods where update events are reported.
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 | Class Summary
95 |
96 | Class
97 | Description
98 |
99 |
100 |
101 | Constants
102 |
103 |
104 |
105 | InAppUpdateManager
106 |
107 | A simple implementation of the Android In-App Update API.
108 |
109 |
110 |
111 | InAppUpdateStatus
112 |
113 | This class is just a wrapper for AppUpdateInfo and InstallState
114 | Used by InAppUpdateManager
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 | Enum Summary
123 |
124 | Enum
125 | Description
126 |
127 |
128 |
129 | Constants.UpdateMode
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
154 |
155 |
156 | Prev Package
157 | Next Package
158 |
159 |
163 |
166 |
167 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
--------------------------------------------------------------------------------
/docs/javadoc/help-doc.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | API Help (library 1.0.1 API)
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
42 |
69 |
70 |
74 |
75 |
76 |
77 | Package
78 | Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain six categories:
79 |
80 | Interfaces (italic)
81 | Classes
82 | Enums
83 | Exceptions
84 | Errors
85 | Annotation Types
86 |
87 |
88 |
89 | Class/Interface
90 | Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:
91 |
92 | Class inheritance diagram
93 | Direct Subclasses
94 | All Known Subinterfaces
95 | All Known Implementing Classes
96 | Class/interface declaration
97 | Class/interface description
98 |
99 |
100 | Nested Class Summary
101 | Field Summary
102 | Constructor Summary
103 | Method Summary
104 |
105 |
106 | Field Detail
107 | Constructor Detail
108 | Method Detail
109 |
110 | Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
111 |
112 |
113 | Annotation Type
114 | Each annotation type has its own separate page with the following sections:
115 |
116 | Annotation Type declaration
117 | Annotation Type description
118 | Required Element Summary
119 | Optional Element Summary
120 | Element Detail
121 |
122 |
123 |
124 | Enum
125 | Each enum has its own separate page with the following sections:
126 |
127 | Enum declaration
128 | Enum description
129 | Enum Constant Summary
130 | Enum Constant Detail
131 |
132 |
133 |
134 | Tree (Class Hierarchy)
135 | There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.
136 |
137 | When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
138 | When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
139 |
140 |
141 |
142 | Deprecated API
143 | The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
144 |
145 |
146 | Index
147 | The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
148 |
149 |
150 | Prev/Next
151 | These links take you to the next or previous class, interface, package, or related page.
152 |
153 |
154 | Frames/No Frames
155 | These links show and hide the HTML frames. All pages are available with or without frames.
156 |
157 |
158 | All Classes
159 | The All Classes link shows all classes and interfaces except non-static nested types.
160 |
161 |
162 | Serialized Form
163 | Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.
164 |
165 |
166 | Constant Field Values
167 | The Constant Field Values page lists the static final fields and their values.
168 |
169 |
170 |
This help file applies to API documentation generated using the standard doclet.
171 |
172 |
188 |
189 |
190 | Prev
191 | Next
192 |
193 |
197 |
200 |
201 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Android In-App Update Library [](https://travis-ci.com/dnKaratzas/android-inapp-update) [  ](https://bintray.com/dkaratzas/maven/android-inapp-update/_latestVersion)
3 |
4 |
5 | This is a simple implementation of the Android In-App Update API.
6 | For more information on InApp Updates you can check the official [documentation](https://developer.android.com/guide/app-bundle/in-app-updates)
7 |
8 | [JavaDocs](https://dnkaratzas.github.io/android-inapp-update/javadoc/) and a [sample app](https://github.com/dnKaratzas/android-inapp-update/tree/master/app/src/main/java/eu/dkaratzas/android/inapp/update/sample) with examples implemented are available.
9 |
10 | # Getting Started
11 |
12 | ## Requirements
13 | * You project should build against Android 4.0 (API level 14) SDK at least.
14 | * In-app updates works only with devices running Android 5.0 (API level 21) or higher.
15 |
16 | ## Add to project
17 | * Add to your project's root `build.gradle` file:
18 | ```groovy
19 | buildscript {
20 | repositories {
21 | jcenter()
22 | }
23 | }
24 | ```
25 | * Add the dependency to your app `build.gradle` file
26 | ```groovy
27 | dependencies {
28 | implementation 'eu.dkaratzas:android-inapp-update:1.0.5'
29 | }
30 | ```
31 |
32 | ## Usage
33 |
34 | There are two update modes.
35 |
36 | - Flexible _**(default)**_ - Shows the user an upgrade dialog but performs the downloading of the update within the background. This means that the user can continue using our app whilst the update is being downloaded. When the update is downloaded asks the user confirmation to perform the install.
37 |
38 | - Immediate - Will trigger a blocking UI until download and installation is finished. Restart is triggered automatically
39 |
40 | ## Flexible
41 |
42 | * With default user confirmation, the InAppUpdateManager is monitoring the flexible update state, provide a default SnackBar that informs the user that installation is ready and requests user confirmation to restart the app.
43 | ```java
44 | @Override
45 | protected void onCreate(Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | setContentView(R.layout.activity_main);
48 |
49 | InAppUpdateManager inAppUpdateManager = InAppUpdateManager.Builder(this, REQ_CODE_VERSION_UPDATE)
50 | .resumeUpdates(true) // Resume the update, if the update was stalled. Default is true
51 | .mode(UpdateMode.FLEXIBLE)
52 | .snackBarMessage("An update has just been downloaded.")
53 | .snackBarAction("RESTART")
54 | .handler(this);
55 |
56 | inAppUpdateManager.checkForAppUpdate();
57 | }
58 | ```
59 |
60 | * With custom user confirmation, need to set the `useCustomNotification(true)` and monitor the update for the `UpdateStatus.DOWNLOADED` status.
61 | Then a notification (or some other UI indication) can be used, to inform the user that installation is ready and requests user confirmation to restart the app. The confirmation must call the `completeUpdate()` method to finish the update.
62 | ```java
63 | public class FlexibleWithCustomNotification extends AppCompatActivity implements InAppUpdateManager.InAppUpdateHandler {
64 | private static final int REQ_CODE_VERSION_UPDATE = 530;
65 | private static final String TAG = "Sample";
66 | private InAppUpdateManager inAppUpdateManager;
67 |
68 | @Override
69 | protected void onCreate(Bundle savedInstanceState) {
70 | super.onCreate(savedInstanceState);
71 | setContentView(R.layout.activity_main);
72 |
73 | inAppUpdateManager = InAppUpdateManager.Builder(this, REQ_CODE_VERSION_UPDATE)
74 | .resumeUpdates(true) // Resume the update, if the update was stalled. Default is true
75 | .mode(UpdateMode.FLEXIBLE)
76 | // default is false. If is set to true you,
77 | // have to manage the user confirmation when
78 | // you detect the InstallStatus.DOWNLOADED status,
79 | .useCustomNotification(true)
80 | .handler(this);
81 |
82 | inAppUpdateManager.checkForAppUpdate();
83 | }
84 |
85 | // InAppUpdateHandler implementation
86 |
87 | @Override
88 | public void onInAppUpdateStatus(InAppUpdateStatus status) {
89 | /*
90 | * If the update downloaded, ask user confirmation and complete the update
91 | */
92 |
93 | if (status.isDownloaded()) {
94 |
95 | View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
96 |
97 | Snackbar snackbar = Snackbar.make(rootView,
98 | "An update has just been downloaded.",
99 | Snackbar.LENGTH_INDEFINITE);
100 |
101 | snackbar.setAction("RESTART", view -> {
102 |
103 | // Triggers the completion of the update of the app for the flexible flow.
104 | inAppUpdateManager.completeUpdate();
105 |
106 | });
107 |
108 | snackbar.show();
109 |
110 | }
111 | }
112 | }
113 | ```
114 |
115 | ## Immediate
116 |
117 |
118 |
119 | To perform an Immediate update, need only to set the mode to `IMMEDIATE` and call the `checkForAppUpdate()` method.
120 | ```java
121 | InAppUpdateManager.Builder(this, REQ_CODE_VERSION_UPDATE)
122 | .resumeUpdates(true) // Resume the update, if the update was stalled. Default is true
123 | .mode(UpdateMode.IMMEDIATE)
124 | .checkForAppUpdate();
125 |
126 | ```
127 |
128 |
129 | ### Forced updates
130 | There are sometimes, that we need to force all users to get a critical update. With Immediate update mode we can achieve such a blocking update mechanism. We need to override `onActivityResult` to detect if the user cancelled the process since the immediate screen can be closed through the back button, and start the update process again.
131 |
132 | ```java
133 | @Override
134 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
135 | if (requestCode == REQ_CODE_VERSION_UPDATE) {
136 | if (resultCode == Activity.RESULT_CANCELED) {
137 | // If the update is cancelled by the user,
138 | // you can request to start the update again.
139 | inAppUpdateManager.checkForAppUpdate();
140 |
141 | Log.d(TAG, "Update flow failed! Result code: " + resultCode);
142 | }
143 | }
144 | super.onActivityResult(requestCode, resultCode, data);
145 | }
146 | ```
147 |
148 | **Note:** You can decide which update should be forced by using for example `Firebase Remote Config` or a `Configuration file hosted on your server`
149 |
150 | ## Troubleshoot
151 | - In-app updates works only with devices running Android 5.0 (API level 21) or higher.
152 | - Testing this won’t work on a debug build. You would need a release build signed with the same key you use to sign your app before uploading to the Play Store. It would be a good time to use the internal testing track.
153 | - In-app updates are available only to user accounts that own the app. So, make sure the account you’re using has downloaded your app from Google Play at least once before using the account to test in-app updates.
154 | - Because Google Play can only update an app to a higher version code, make sure the app you are testing as a lower version code than the update version code.
155 | - Make sure the account is eligible and the Google Play cache is up to date. To do so, while logged into the Google Play Store account on the test device, proceed as follows:
156 | 1. Make sure you completely [close the Google Play Store App](https://support.google.com/android/answer/9079646#close_apps).
157 | 2. Open the Google Play Store app and go to the **My Apps & Games** tab.
158 | 3. If the app you are testing doesn’t appear with an available update, check that you’ve properly [set up your testing tracks](https://support.google.com/googleplay/android-developer/answer/3131213?hl=en).
159 | ## License
160 |
161 | Copyright 2019 Dionysios Karatzas
162 |
163 | Licensed under the Apache License, Version 2.0 (the "License");
164 | you may not use this file except in compliance with the License.
165 | You may obtain a copy of the License at
166 |
167 | http://www.apache.org/licenses/LICENSE-2.0
168 |
169 | Unless required by applicable law or agreed to in writing, software
170 | distributed under the License is distributed on an "AS IS" BASIS,
171 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
172 | See the License for the specific language governing permissions and
173 | limitations under the License.
174 |
175 |
176 | ## Contributing
177 |
178 | 1. Fork it
179 | 2. Create your feature branch (`git checkout -b my-new-feature`)
180 | 3. Commit your changes (`git commit -am 'Add some feature'`)
181 | 4. Push to the branch (`git push origin my-new-feature`)
182 | 5. **Create New Pull Request**
183 |
--------------------------------------------------------------------------------
/docs/javadoc/eu/dkaratzas/android/inapp/update/InAppUpdateManager.InAppUpdateHandler.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | InAppUpdateManager.InAppUpdateHandler (library 1.0.1 API)
7 |
8 |
9 |
10 |
11 |
12 |
28 |
29 | JavaScript is disabled on your browser.
30 |
31 |
32 |
48 |
49 |
53 |
57 |
60 |
61 |
71 |
72 |
73 |
74 | Summary:
75 | Nested |
76 | Field |
77 | Constr |
78 | Method
79 |
80 |
81 | Detail:
82 | Field |
83 | Constr |
84 | Method
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
96 |
97 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 | Method Summary
120 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 | Method Detail
154 |
155 |
156 |
157 |
170 |
171 |
172 |
173 |
174 |
175 | onInAppUpdateStatus
176 | void onInAppUpdateStatus(InAppUpdateStatus status)
177 | Monitoring the update state of the flexible downloads.
178 | For immediate updates, Google Play takes care of downloading and installing the update for you.
179 |
180 | Parameters:
181 | status - the status
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
209 |
210 |
214 |
218 |
221 |
222 |
232 |
233 |
234 |
235 | Summary:
236 | Nested |
237 | Field |
238 | Constr |
239 | Method
240 |
241 |
242 | Detail:
243 | Field |
244 | Constr |
245 | Method
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
--------------------------------------------------------------------------------
/docs/javadoc/eu/dkaratzas/android/inapp/update/Constants.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Constants (library 1.0.1 API)
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
42 |
43 |
47 |
51 |
54 |
55 |
65 |
66 |
67 |
74 |
75 | Detail:
76 | Field |
77 | Constr |
78 | Method
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
90 |
91 |
92 | java.lang.Object
93 |
94 |
95 | eu.dkaratzas.android.inapp.update.Constants
96 |
97 |
98 |
99 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 | Nested Class Summary
118 |
119 | Nested Classes
120 |
121 | Modifier and Type
122 | Class and Description
123 |
124 |
125 | static class
126 | Constants.UpdateMode
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 | Field Summary
137 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 | Constructor Summary
160 |
161 | Constructors
162 |
163 | Constructor and Description
164 |
165 |
166 | Constants ()
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 | Method Summary
177 |
178 |
179 |
180 |
181 | Methods inherited from class java.lang.Object
182 | clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
226 |
227 |
228 |
229 |
230 |
231 | Constructor Detail
232 |
233 |
234 |
235 |
236 |
237 | Constants
238 | public Constants()
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
265 |
266 |
270 |
274 |
277 |
278 |
288 |
289 |
290 |
297 |
298 | Detail:
299 | Field |
300 | Constr |
301 | Method
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright 2016-2018 Samuel Wall
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/docs/javadoc/eu/dkaratzas/android/inapp/update/InAppUpdateStatus.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | InAppUpdateStatus (library 1.0.1 API)
7 |
8 |
9 |
10 |
11 |
12 |
28 |
29 | JavaScript is disabled on your browser.
30 |
31 |
32 |
48 |
49 |
53 |
57 |
60 |
61 |
71 |
72 |
73 |
74 | Summary:
75 | Nested |
76 | Field |
77 | Constr |
78 | Method
79 |
80 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
96 |
97 |
98 | java.lang.Object
99 |
100 |
101 | eu.dkaratzas.android.inapp.update.InAppUpdateStatus
102 |
103 |
104 |
105 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 | Constructor Summary
126 |
127 | Constructors
128 |
129 | Constructor and Description
130 |
131 |
132 | InAppUpdateStatus ()
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 | Method Summary
143 |
178 |
179 |
180 |
181 |
182 | Methods inherited from class java.lang.Object
183 | clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
210 |
211 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
303 |
304 |
308 |
312 |
315 |
316 |
326 |
327 |
328 |
329 | Summary:
330 | Nested |
331 | Field |
332 | Constr |
333 | Method
334 |
335 |
336 | Detail:
337 | Field |
338 | Constr |
339 | Method
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
--------------------------------------------------------------------------------
/docs/javadoc/eu/dkaratzas/android/inapp/update/Constants.UpdateMode.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Constants.UpdateMode (library 1.0.1 API)
7 |
8 |
9 |
10 |
11 |
12 |
28 |
29 | JavaScript is disabled on your browser.
30 |
31 |
32 |
48 |
49 |
53 |
57 |
60 |
61 |
71 |
72 |
87 |
88 |
89 |
90 |
91 |
92 |
96 |
97 |
98 | java.lang.Object
99 |
100 |
101 | java.lang.Enum<Constants.UpdateMode >
102 |
103 |
104 | eu.dkaratzas.android.inapp.update.Constants.UpdateMode
105 |
106 |
107 |
108 |
109 |
110 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 | Enum Constant Summary
137 |
138 | Enum Constants
139 |
140 | Enum Constant and Description
141 |
142 |
143 | FLEXIBLE
144 |
145 |
146 | IMMEDIATE
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 | Method Summary
157 |
158 | All Methods Static Methods Concrete Methods
159 |
160 | Modifier and Type
161 | Method and Description
162 |
163 |
164 | static Constants.UpdateMode
165 | valueOf (java.lang.String name)
166 | Returns the enum constant of this type with the specified name.
167 |
168 |
169 |
170 | static Constants.UpdateMode []
171 | values ()
172 | Returns an array containing the constants of this enum type, in
173 | the order they are declared.
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 | Methods inherited from class java.lang.Enum
182 | clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
183 |
184 |
185 |
186 |
187 |
188 | Methods inherited from class java.lang.Object
189 | getClass, notify, notifyAll, wait, wait, wait
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
225 |
226 |
227 |
228 |
229 |
230 | Method Detail
231 |
232 |
233 |
234 |
251 |
252 |
253 |
254 |
255 |
256 | valueOf
257 | public static Constants.UpdateMode valueOf(java.lang.String name)
258 | Returns the enum constant of this type with the specified name.
259 | The string must match exactly an identifier used to declare an
260 | enum constant in this type. (Extraneous whitespace characters are
261 | not permitted.)
262 |
263 | Parameters:
264 | name - the name of the enum constant to be returned.
265 | Returns:
266 | the enum constant with the specified name
267 | Throws:
268 | java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
269 | java.lang.NullPointerException - if the argument is null
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
297 |
298 |
302 |
306 |
309 |
310 |
320 |
321 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
--------------------------------------------------------------------------------
/docs/javadoc/stylesheet.css:
--------------------------------------------------------------------------------
1 | /* Javadoc style sheet */
2 | /*
3 | Overall document style
4 | */
5 |
6 | @import url('resources/fonts/dejavu.css');
7 |
8 | body {
9 | background-color:#ffffff;
10 | color:#353833;
11 | font-family:'DejaVu Sans', Arial, Helvetica, sans-serif;
12 | font-size:14px;
13 | margin:0;
14 | }
15 | a:link, a:visited {
16 | text-decoration:none;
17 | color:#4A6782;
18 | }
19 | a:hover, a:focus {
20 | text-decoration:none;
21 | color:#bb7a2a;
22 | }
23 | a:active {
24 | text-decoration:none;
25 | color:#4A6782;
26 | }
27 | a[name] {
28 | color:#353833;
29 | }
30 | a[name]:hover {
31 | text-decoration:none;
32 | color:#353833;
33 | }
34 | pre {
35 | font-family:'DejaVu Sans Mono', monospace;
36 | font-size:14px;
37 | }
38 | h1 {
39 | font-size:20px;
40 | }
41 | h2 {
42 | font-size:18px;
43 | }
44 | h3 {
45 | font-size:16px;
46 | font-style:italic;
47 | }
48 | h4 {
49 | font-size:13px;
50 | }
51 | h5 {
52 | font-size:12px;
53 | }
54 | h6 {
55 | font-size:11px;
56 | }
57 | ul {
58 | list-style-type:disc;
59 | }
60 | code, tt {
61 | font-family:'DejaVu Sans Mono', monospace;
62 | font-size:14px;
63 | padding-top:4px;
64 | margin-top:8px;
65 | line-height:1.4em;
66 | }
67 | dt code {
68 | font-family:'DejaVu Sans Mono', monospace;
69 | font-size:14px;
70 | padding-top:4px;
71 | }
72 | table tr td dt code {
73 | font-family:'DejaVu Sans Mono', monospace;
74 | font-size:14px;
75 | vertical-align:top;
76 | padding-top:4px;
77 | }
78 | sup {
79 | font-size:8px;
80 | }
81 | /*
82 | Document title and Copyright styles
83 | */
84 | .clear {
85 | clear:both;
86 | height:0px;
87 | overflow:hidden;
88 | }
89 | .aboutLanguage {
90 | float:right;
91 | padding:0px 21px;
92 | font-size:11px;
93 | z-index:200;
94 | margin-top:-9px;
95 | }
96 | .legalCopy {
97 | margin-left:.5em;
98 | }
99 | .bar a, .bar a:link, .bar a:visited, .bar a:active {
100 | color:#FFFFFF;
101 | text-decoration:none;
102 | }
103 | .bar a:hover, .bar a:focus {
104 | color:#bb7a2a;
105 | }
106 | .tab {
107 | background-color:#0066FF;
108 | color:#ffffff;
109 | padding:8px;
110 | width:5em;
111 | font-weight:bold;
112 | }
113 | /*
114 | Navigation bar styles
115 | */
116 | .bar {
117 | background-color:#4D7A97;
118 | color:#FFFFFF;
119 | padding:.8em .5em .4em .8em;
120 | height:auto;/*height:1.8em;*/
121 | font-size:11px;
122 | margin:0;
123 | }
124 | .topNav {
125 | background-color:#4D7A97;
126 | color:#FFFFFF;
127 | float:left;
128 | padding:0;
129 | width:100%;
130 | clear:right;
131 | height:2.8em;
132 | padding-top:10px;
133 | overflow:hidden;
134 | font-size:12px;
135 | }
136 | .bottomNav {
137 | margin-top:10px;
138 | background-color:#4D7A97;
139 | color:#FFFFFF;
140 | float:left;
141 | padding:0;
142 | width:100%;
143 | clear:right;
144 | height:2.8em;
145 | padding-top:10px;
146 | overflow:hidden;
147 | font-size:12px;
148 | }
149 | .subNav {
150 | background-color:#dee3e9;
151 | float:left;
152 | width:100%;
153 | overflow:hidden;
154 | font-size:12px;
155 | }
156 | .subNav div {
157 | clear:left;
158 | float:left;
159 | padding:0 0 5px 6px;
160 | text-transform:uppercase;
161 | }
162 | ul.navList, ul.subNavList {
163 | float:left;
164 | margin:0 25px 0 0;
165 | padding:0;
166 | }
167 | ul.navList li{
168 | list-style:none;
169 | float:left;
170 | padding: 5px 6px;
171 | text-transform:uppercase;
172 | }
173 | ul.subNavList li{
174 | list-style:none;
175 | float:left;
176 | }
177 | .topNav a:link, .topNav a:active, .topNav a:visited, .bottomNav a:link, .bottomNav a:active, .bottomNav a:visited {
178 | color:#FFFFFF;
179 | text-decoration:none;
180 | text-transform:uppercase;
181 | }
182 | .topNav a:hover, .bottomNav a:hover {
183 | text-decoration:none;
184 | color:#bb7a2a;
185 | text-transform:uppercase;
186 | }
187 | .navBarCell1Rev {
188 | background-color:#F8981D;
189 | color:#253441;
190 | margin: auto 5px;
191 | }
192 | .skipNav {
193 | position:absolute;
194 | top:auto;
195 | left:-9999px;
196 | overflow:hidden;
197 | }
198 | /*
199 | Page header and footer styles
200 | */
201 | .header, .footer {
202 | clear:both;
203 | margin:0 20px;
204 | padding:5px 0 0 0;
205 | }
206 | .indexHeader {
207 | margin:10px;
208 | position:relative;
209 | }
210 | .indexHeader span{
211 | margin-right:15px;
212 | }
213 | .indexHeader h1 {
214 | font-size:13px;
215 | }
216 | .title {
217 | color:#2c4557;
218 | margin:10px 0;
219 | }
220 | .subTitle {
221 | margin:5px 0 0 0;
222 | }
223 | .header ul {
224 | margin:0 0 15px 0;
225 | padding:0;
226 | }
227 | .footer ul {
228 | margin:20px 0 5px 0;
229 | }
230 | .header ul li, .footer ul li {
231 | list-style:none;
232 | font-size:13px;
233 | }
234 | /*
235 | Heading styles
236 | */
237 | div.details ul.blockList ul.blockList ul.blockList li.blockList h4, div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 {
238 | background-color:#dee3e9;
239 | border:1px solid #d0d9e0;
240 | margin:0 0 6px -8px;
241 | padding:7px 5px;
242 | }
243 | ul.blockList ul.blockList ul.blockList li.blockList h3 {
244 | background-color:#dee3e9;
245 | border:1px solid #d0d9e0;
246 | margin:0 0 6px -8px;
247 | padding:7px 5px;
248 | }
249 | ul.blockList ul.blockList li.blockList h3 {
250 | padding:0;
251 | margin:15px 0;
252 | }
253 | ul.blockList li.blockList h2 {
254 | padding:0px 0 20px 0;
255 | }
256 | /*
257 | Page layout container styles
258 | */
259 | .contentContainer, .sourceContainer, .classUseContainer, .serializedFormContainer, .constantValuesContainer {
260 | clear:both;
261 | padding:10px 20px;
262 | position:relative;
263 | }
264 | .indexContainer {
265 | margin:10px;
266 | position:relative;
267 | font-size:12px;
268 | }
269 | .indexContainer h2 {
270 | font-size:13px;
271 | padding:0 0 3px 0;
272 | }
273 | .indexContainer ul {
274 | margin:0;
275 | padding:0;
276 | }
277 | .indexContainer ul li {
278 | list-style:none;
279 | padding-top:2px;
280 | }
281 | .contentContainer .description dl dt, .contentContainer .details dl dt, .serializedFormContainer dl dt {
282 | font-size:12px;
283 | font-weight:bold;
284 | margin:10px 0 0 0;
285 | color:#4E4E4E;
286 | }
287 | .contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd {
288 | margin:5px 0 10px 0px;
289 | font-size:14px;
290 | font-family:'DejaVu Sans Mono',monospace;
291 | }
292 | .serializedFormContainer dl.nameValue dt {
293 | margin-left:1px;
294 | font-size:1.1em;
295 | display:inline;
296 | font-weight:bold;
297 | }
298 | .serializedFormContainer dl.nameValue dd {
299 | margin:0 0 0 1px;
300 | font-size:1.1em;
301 | display:inline;
302 | }
303 | /*
304 | List styles
305 | */
306 | ul.horizontal li {
307 | display:inline;
308 | font-size:0.9em;
309 | }
310 | ul.inheritance {
311 | margin:0;
312 | padding:0;
313 | }
314 | ul.inheritance li {
315 | display:inline;
316 | list-style:none;
317 | }
318 | ul.inheritance li ul.inheritance {
319 | margin-left:15px;
320 | padding-left:15px;
321 | padding-top:1px;
322 | }
323 | ul.blockList, ul.blockListLast {
324 | margin:10px 0 10px 0;
325 | padding:0;
326 | }
327 | ul.blockList li.blockList, ul.blockListLast li.blockList {
328 | list-style:none;
329 | margin-bottom:15px;
330 | line-height:1.4;
331 | }
332 | ul.blockList ul.blockList li.blockList, ul.blockList ul.blockListLast li.blockList {
333 | padding:0px 20px 5px 10px;
334 | border:1px solid #ededed;
335 | background-color:#f8f8f8;
336 | }
337 | ul.blockList ul.blockList ul.blockList li.blockList, ul.blockList ul.blockList ul.blockListLast li.blockList {
338 | padding:0 0 5px 8px;
339 | background-color:#ffffff;
340 | border:none;
341 | }
342 | ul.blockList ul.blockList ul.blockList ul.blockList li.blockList {
343 | margin-left:0;
344 | padding-left:0;
345 | padding-bottom:15px;
346 | border:none;
347 | }
348 | ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast {
349 | list-style:none;
350 | border-bottom:none;
351 | padding-bottom:0;
352 | }
353 | table tr td dl, table tr td dl dt, table tr td dl dd {
354 | margin-top:0;
355 | margin-bottom:1px;
356 | }
357 | /*
358 | Table styles
359 | */
360 | .overviewSummary, .memberSummary, .typeSummary, .useSummary, .constantsSummary, .deprecatedSummary {
361 | width:100%;
362 | border-left:1px solid #EEE;
363 | border-right:1px solid #EEE;
364 | border-bottom:1px solid #EEE;
365 | }
366 | .overviewSummary, .memberSummary {
367 | padding:0px;
368 | }
369 | .overviewSummary caption, .memberSummary caption, .typeSummary caption,
370 | .useSummary caption, .constantsSummary caption, .deprecatedSummary caption {
371 | position:relative;
372 | text-align:left;
373 | background-repeat:no-repeat;
374 | color:#253441;
375 | font-weight:bold;
376 | clear:none;
377 | overflow:hidden;
378 | padding:0px;
379 | padding-top:10px;
380 | padding-left:1px;
381 | margin:0px;
382 | white-space:pre;
383 | }
384 | .overviewSummary caption a:link, .memberSummary caption a:link, .typeSummary caption a:link,
385 | .useSummary caption a:link, .constantsSummary caption a:link, .deprecatedSummary caption a:link,
386 | .overviewSummary caption a:hover, .memberSummary caption a:hover, .typeSummary caption a:hover,
387 | .useSummary caption a:hover, .constantsSummary caption a:hover, .deprecatedSummary caption a:hover,
388 | .overviewSummary caption a:active, .memberSummary caption a:active, .typeSummary caption a:active,
389 | .useSummary caption a:active, .constantsSummary caption a:active, .deprecatedSummary caption a:active,
390 | .overviewSummary caption a:visited, .memberSummary caption a:visited, .typeSummary caption a:visited,
391 | .useSummary caption a:visited, .constantsSummary caption a:visited, .deprecatedSummary caption a:visited {
392 | color:#FFFFFF;
393 | }
394 | .overviewSummary caption span, .memberSummary caption span, .typeSummary caption span,
395 | .useSummary caption span, .constantsSummary caption span, .deprecatedSummary caption span {
396 | white-space:nowrap;
397 | padding-top:5px;
398 | padding-left:12px;
399 | padding-right:12px;
400 | padding-bottom:7px;
401 | display:inline-block;
402 | float:left;
403 | background-color:#F8981D;
404 | border: none;
405 | height:16px;
406 | }
407 | .memberSummary caption span.activeTableTab span {
408 | white-space:nowrap;
409 | padding-top:5px;
410 | padding-left:12px;
411 | padding-right:12px;
412 | margin-right:3px;
413 | display:inline-block;
414 | float:left;
415 | background-color:#F8981D;
416 | height:16px;
417 | }
418 | .memberSummary caption span.tableTab span {
419 | white-space:nowrap;
420 | padding-top:5px;
421 | padding-left:12px;
422 | padding-right:12px;
423 | margin-right:3px;
424 | display:inline-block;
425 | float:left;
426 | background-color:#4D7A97;
427 | height:16px;
428 | }
429 | .memberSummary caption span.tableTab, .memberSummary caption span.activeTableTab {
430 | padding-top:0px;
431 | padding-left:0px;
432 | padding-right:0px;
433 | background-image:none;
434 | float:none;
435 | display:inline;
436 | }
437 | .overviewSummary .tabEnd, .memberSummary .tabEnd, .typeSummary .tabEnd,
438 | .useSummary .tabEnd, .constantsSummary .tabEnd, .deprecatedSummary .tabEnd {
439 | display:none;
440 | width:5px;
441 | position:relative;
442 | float:left;
443 | background-color:#F8981D;
444 | }
445 | .memberSummary .activeTableTab .tabEnd {
446 | display:none;
447 | width:5px;
448 | margin-right:3px;
449 | position:relative;
450 | float:left;
451 | background-color:#F8981D;
452 | }
453 | .memberSummary .tableTab .tabEnd {
454 | display:none;
455 | width:5px;
456 | margin-right:3px;
457 | position:relative;
458 | background-color:#4D7A97;
459 | float:left;
460 |
461 | }
462 | .overviewSummary td, .memberSummary td, .typeSummary td,
463 | .useSummary td, .constantsSummary td, .deprecatedSummary td {
464 | text-align:left;
465 | padding:0px 0px 12px 10px;
466 | }
467 | th.colOne, th.colFirst, th.colLast, .useSummary th, .constantsSummary th,
468 | td.colOne, td.colFirst, td.colLast, .useSummary td, .constantsSummary td{
469 | vertical-align:top;
470 | padding-right:0px;
471 | padding-top:8px;
472 | padding-bottom:3px;
473 | }
474 | th.colFirst, th.colLast, th.colOne, .constantsSummary th {
475 | background:#dee3e9;
476 | text-align:left;
477 | padding:8px 3px 3px 7px;
478 | }
479 | td.colFirst, th.colFirst {
480 | white-space:nowrap;
481 | font-size:13px;
482 | }
483 | td.colLast, th.colLast {
484 | font-size:13px;
485 | }
486 | td.colOne, th.colOne {
487 | font-size:13px;
488 | }
489 | .overviewSummary td.colFirst, .overviewSummary th.colFirst,
490 | .useSummary td.colFirst, .useSummary th.colFirst,
491 | .overviewSummary td.colOne, .overviewSummary th.colOne,
492 | .memberSummary td.colFirst, .memberSummary th.colFirst,
493 | .memberSummary td.colOne, .memberSummary th.colOne,
494 | .typeSummary td.colFirst{
495 | width:25%;
496 | vertical-align:top;
497 | }
498 | td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover {
499 | font-weight:bold;
500 | }
501 | .tableSubHeadingColor {
502 | background-color:#EEEEFF;
503 | }
504 | .altColor {
505 | background-color:#FFFFFF;
506 | }
507 | .rowColor {
508 | background-color:#EEEEEF;
509 | }
510 | /*
511 | Content styles
512 | */
513 | .description pre {
514 | margin-top:0;
515 | }
516 | .deprecatedContent {
517 | margin:0;
518 | padding:10px 0;
519 | }
520 | .docSummary {
521 | padding:0;
522 | }
523 |
524 | ul.blockList ul.blockList ul.blockList li.blockList h3 {
525 | font-style:normal;
526 | }
527 |
528 | div.block {
529 | font-size:14px;
530 | font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif;
531 | }
532 |
533 | td.colLast div {
534 | padding-top:0px;
535 | }
536 |
537 |
538 | td.colLast a {
539 | padding-bottom:3px;
540 | }
541 | /*
542 | Formatting effect styles
543 | */
544 | .sourceLineNo {
545 | color:green;
546 | padding:0 30px 0 0;
547 | }
548 | h1.hidden {
549 | visibility:hidden;
550 | overflow:hidden;
551 | font-size:10px;
552 | }
553 | .block {
554 | display:block;
555 | margin:3px 10px 2px 0px;
556 | color:#474747;
557 | }
558 | .deprecatedLabel, .descfrmTypeLabel, .memberNameLabel, .memberNameLink,
559 | .overrideSpecifyLabel, .packageHierarchyLabel, .paramLabel, .returnLabel,
560 | .seeLabel, .simpleTagLabel, .throwsLabel, .typeNameLabel, .typeNameLink {
561 | font-weight:bold;
562 | }
563 | .deprecationComment, .emphasizedPhrase, .interfaceName {
564 | font-style:italic;
565 | }
566 |
567 | div.block div.block span.deprecationComment, div.block div.block span.emphasizedPhrase,
568 | div.block div.block span.interfaceName {
569 | font-style:normal;
570 | }
571 |
572 | div.contentContainer ul.blockList li.blockList h2{
573 | padding-bottom:0px;
574 | }
575 |
--------------------------------------------------------------------------------
/library/src/main/java/eu/dkaratzas/android/inapp/update/InAppUpdateManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Dionysios Karatzas
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.dkaratzas.android.inapp.update;
18 |
19 | import android.content.IntentSender;
20 | import android.util.Log;
21 | import android.view.View;
22 |
23 | import androidx.appcompat.app.AppCompatActivity;
24 | import androidx.lifecycle.Lifecycle;
25 | import androidx.lifecycle.LifecycleObserver;
26 | import androidx.lifecycle.OnLifecycleEvent;
27 |
28 | import com.google.android.material.snackbar.Snackbar;
29 | import com.google.android.play.core.appupdate.AppUpdateInfo;
30 | import com.google.android.play.core.appupdate.AppUpdateManager;
31 | import com.google.android.play.core.appupdate.AppUpdateManagerFactory;
32 | import com.google.android.play.core.install.InstallState;
33 | import com.google.android.play.core.install.InstallStateUpdatedListener;
34 | import com.google.android.play.core.install.model.AppUpdateType;
35 | import com.google.android.play.core.install.model.InstallStatus;
36 | import com.google.android.play.core.install.model.UpdateAvailability;
37 | import com.google.android.play.core.tasks.OnSuccessListener;
38 | import com.google.android.play.core.tasks.Task;
39 |
40 | import static eu.dkaratzas.android.inapp.update.Constants.UpdateMode;
41 |
42 | /**
43 | * A simple implementation of the Android In-App Update API.
44 | *
45 | *
46 | *
In-App Updates
47 | *
For more information about In-App Updates you can check the official
48 | * documentation
49 | *
50 | *
51 | */
52 | public class InAppUpdateManager implements LifecycleObserver {
53 |
54 | /**
55 | * Callback methods where update events are reported.
56 | */
57 | public interface InAppUpdateHandler {
58 | /**
59 | * On update error.
60 | *
61 | * @param code the code
62 | * @param error the error
63 | */
64 | void onInAppUpdateError(int code, Throwable error);
65 |
66 |
67 | /**
68 | * Monitoring the update state of the flexible downloads.
69 | * For immediate updates, Google Play takes care of downloading and installing the update for you.
70 | *
71 | * @param status the status
72 | */
73 | void onInAppUpdateStatus(InAppUpdateStatus status);
74 | }
75 |
76 | // region Declarations
77 | private static final String LOG_TAG = "InAppUpdateManager";
78 | private AppCompatActivity activity;
79 | private AppUpdateManager appUpdateManager;
80 | private int requestCode = 64534;
81 | private String snackBarMessage = "An update has just been downloaded.";
82 | private String snackBarAction = "RESTART";
83 | private UpdateMode mode = UpdateMode.FLEXIBLE;
84 | private boolean resumeUpdates = true;
85 | private boolean useCustomNotification = false;
86 | private InAppUpdateHandler handler;
87 | private Snackbar snackbar;
88 | private InAppUpdateStatus inAppUpdateStatus = new InAppUpdateStatus();
89 |
90 |
91 | private InstallStateUpdatedListener installStateUpdatedListener = new InstallStateUpdatedListener() {
92 | @Override
93 | public void onStateUpdate(InstallState installState) {
94 | inAppUpdateStatus.setInstallState(installState);
95 |
96 | reportStatus();
97 |
98 | // Show module progress, log state, or install the update.
99 | if (installState.installStatus() == InstallStatus.DOWNLOADED) {
100 | // After the update is downloaded, show a notification
101 | // and request user confirmation to restart the app.
102 | popupSnackbarForUserConfirmation();
103 | }
104 | }
105 | };
106 | //endregion
107 |
108 | //region Constructor
109 | private static InAppUpdateManager instance;
110 |
111 | /**
112 | * Creates a builder that uses the default requestCode.
113 | *
114 | * @param activity the activity
115 | * @return a new {@link InAppUpdateManager} instance
116 | */
117 | public static InAppUpdateManager Builder(AppCompatActivity activity) {
118 | if (instance == null) {
119 | instance = new InAppUpdateManager(activity);
120 | }
121 | return instance;
122 | }
123 |
124 | /**
125 | * Creates a builder
126 | *
127 | * @param activity the activity
128 | * @param requestCode the request code to later monitor this update request via onActivityResult()
129 | * @return a new {@link InAppUpdateManager} instance
130 | */
131 | public static InAppUpdateManager Builder(AppCompatActivity activity, int requestCode) {
132 | if (instance == null) {
133 | instance = new InAppUpdateManager(activity, requestCode);
134 | }
135 | return instance;
136 | }
137 |
138 | private InAppUpdateManager(AppCompatActivity activity) {
139 | this.activity = activity;
140 | setupSnackbar();
141 |
142 | init();
143 | }
144 |
145 | private InAppUpdateManager(AppCompatActivity activity, int requestCode) {
146 | this.activity = activity;
147 | this.requestCode = requestCode;
148 |
149 | init();
150 | }
151 |
152 | private void init() {
153 | setupSnackbar();
154 |
155 | appUpdateManager = AppUpdateManagerFactory.create(this.activity);
156 |
157 | activity.getLifecycle().addObserver(this);
158 |
159 | if (mode == UpdateMode.FLEXIBLE)
160 | appUpdateManager.registerListener(installStateUpdatedListener);
161 |
162 | checkForUpdate(false);
163 | }
164 | //endregion
165 |
166 | // region Setters
167 |
168 | /**
169 | * Set the update mode.
170 | *
171 | * @param mode the update mode
172 | * @return the update manager instance
173 | */
174 | public InAppUpdateManager mode(UpdateMode mode) {
175 | this.mode = mode;
176 | return this;
177 | }
178 |
179 | /**
180 | * Checks that the update is not stalled during 'onResume()'.
181 | * If the update is downloaded but not installed, will notify
182 | * the user to complete the update.
183 | *
184 | * @param resumeUpdates the resume updates
185 | * @return the update manager instance
186 | */
187 | public InAppUpdateManager resumeUpdates(boolean resumeUpdates) {
188 | this.resumeUpdates = resumeUpdates;
189 | return this;
190 | }
191 |
192 | /**
193 | * Set the callback handler
194 | *
195 | * @param handler the handler
196 | * @return the update manager instance
197 | */
198 | public InAppUpdateManager handler(InAppUpdateHandler handler) {
199 | this.handler = handler;
200 | return this;
201 | }
202 |
203 | /**
204 | * Use custom notification for the user confirmation needed by the {@link UpdateMode#FLEXIBLE} flow.
205 | * If this will set to true, need to implement the {@link InAppUpdateHandler} and listen for the {@link InAppUpdateStatus#isDownloaded()} status
206 | * via {@link InAppUpdateHandler#onInAppUpdateStatus} callback. Then a notification (or some other UI indication) can be used,
207 | * to inform the user that installation is ready and requests user confirmation to restart the app. The confirmation must
208 | * call the {@link #completeUpdate} method to finish the update.
209 | *
210 | * @param useCustomNotification use custom user confirmation
211 | * @return the update manager instance
212 | */
213 | public InAppUpdateManager useCustomNotification(boolean useCustomNotification) {
214 | this.useCustomNotification = useCustomNotification;
215 | return this;
216 | }
217 |
218 | public InAppUpdateManager snackBarMessage(String snackBarMessage) {
219 | this.snackBarMessage = snackBarMessage;
220 | setupSnackbar();
221 | return this;
222 | }
223 |
224 | public InAppUpdateManager snackBarAction(String snackBarAction) {
225 | this.snackBarAction = snackBarAction;
226 | setupSnackbar();
227 | return this;
228 | }
229 |
230 |
231 | public InAppUpdateManager snackBarActionColor(int color) {
232 | snackbar.setActionTextColor(color);
233 | return this;
234 | }
235 |
236 | //endregion
237 |
238 | //region Lifecycle
239 | @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
240 | public void onResume() {
241 | if (resumeUpdates)
242 | checkNewAppVersionState();
243 | }
244 |
245 |
246 | @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
247 | public void onDestroy() {
248 | unregisterListener();
249 | }
250 | //endregion
251 |
252 | //region Methods
253 |
254 | /**
255 | * Check for update availability. If there will be an update available
256 | * will start the update process with the selected {@link UpdateMode}.
257 | */
258 | public void checkForAppUpdate() {
259 | checkForUpdate(true);
260 | }
261 |
262 | /**
263 | * Triggers the completion of the app update for the flexible flow.
264 | */
265 | public void completeUpdate() {
266 | appUpdateManager.completeUpdate();
267 | }
268 | //endregion
269 |
270 | //region Private Methods
271 |
272 | /**
273 | * Check for update availability. If there will be an update available
274 | * will start the update process with the selected {@link UpdateMode}.
275 | */
276 | private void checkForUpdate(final boolean startUpdate) {
277 |
278 | // Returns an intent object that you use to check for an update.
279 | Task appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
280 |
281 |
282 | // Checks that the platform will allow the specified type of update.
283 | appUpdateInfoTask.addOnSuccessListener(new OnSuccessListener() {
284 | @Override
285 | public void onSuccess(AppUpdateInfo appUpdateInfo) {
286 | inAppUpdateStatus.setAppUpdateInfo(appUpdateInfo);
287 |
288 | if (startUpdate) {
289 | if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) {
290 | // Request the update.
291 | if (mode == UpdateMode.FLEXIBLE && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
292 | // Start an update.
293 | startAppUpdateFlexible(appUpdateInfo);
294 | } else if (appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
295 | // Start an update.
296 | startAppUpdateImmediate(appUpdateInfo);
297 | }
298 |
299 | Log.d(LOG_TAG, "checkForAppUpdate(): Update available. Version Code: " + appUpdateInfo.availableVersionCode());
300 | } else if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_NOT_AVAILABLE) {
301 | Log.d(LOG_TAG, "checkForAppUpdate(): No Update available. Code: " + appUpdateInfo.updateAvailability());
302 | }
303 | }
304 |
305 | reportStatus();
306 | }
307 | });
308 |
309 | }
310 |
311 | private void startAppUpdateImmediate(AppUpdateInfo appUpdateInfo) {
312 | try {
313 | appUpdateManager.startUpdateFlowForResult(
314 | appUpdateInfo,
315 | AppUpdateType.IMMEDIATE,
316 | // The current activity making the update request.
317 | activity,
318 | // Include a request code to later monitor this update request.
319 | requestCode);
320 | } catch (IntentSender.SendIntentException e) {
321 | Log.e(LOG_TAG, "error in startAppUpdateImmediate", e);
322 | reportUpdateError(Constants.UPDATE_ERROR_START_APP_UPDATE_IMMEDIATE, e);
323 | }
324 | }
325 |
326 | private void startAppUpdateFlexible(AppUpdateInfo appUpdateInfo) {
327 | try {
328 | appUpdateManager.startUpdateFlowForResult(
329 | appUpdateInfo,
330 | AppUpdateType.FLEXIBLE,
331 | // The current activity making the update request.
332 | activity,
333 | // Include a request code to later monitor this update request.
334 | requestCode);
335 | } catch (IntentSender.SendIntentException e) {
336 | Log.e(LOG_TAG, "error in startAppUpdateFlexible", e);
337 | reportUpdateError(Constants.UPDATE_ERROR_START_APP_UPDATE_FLEXIBLE, e);
338 | }
339 | }
340 |
341 | /**
342 | * Displays the snackbar notification and call to action.
343 | * Needed only for Flexible app update
344 | */
345 | private void popupSnackbarForUserConfirmation() {
346 | if (!useCustomNotification) {
347 | if (snackbar != null && snackbar.isShownOrQueued())
348 | snackbar.dismiss();
349 |
350 |
351 | snackbar.show();
352 | }
353 | }
354 |
355 | /**
356 | * Checks that the update is not stalled during 'onResume()'.
357 | * However, you should execute this check at all app entry points.
358 | */
359 | private void checkNewAppVersionState() {
360 |
361 | appUpdateManager
362 | .getAppUpdateInfo()
363 | .addOnSuccessListener(new OnSuccessListener() {
364 | @Override
365 | public void onSuccess(AppUpdateInfo appUpdateInfo) {
366 |
367 | inAppUpdateStatus.setAppUpdateInfo(appUpdateInfo);
368 |
369 | //FLEXIBLE:
370 | // If the update is downloaded but not installed,
371 | // notify the user to complete the update.
372 | if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) {
373 | popupSnackbarForUserConfirmation();
374 | reportStatus();
375 | Log.d(LOG_TAG, "checkNewAppVersionState(): resuming flexible update. Code: " + appUpdateInfo.updateAvailability());
376 | }
377 |
378 | //IMMEDIATE:
379 | if (appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
380 | // If an in-app update is already running, resume the update.
381 | startAppUpdateImmediate(appUpdateInfo);
382 |
383 | Log.d(LOG_TAG, "checkNewAppVersionState(): resuming immediate update. Code: " + appUpdateInfo.updateAvailability());
384 |
385 | }
386 | }
387 | });
388 |
389 | }
390 |
391 | private void setupSnackbar() {
392 | View rootView = activity.getWindow().getDecorView().findViewById(android.R.id.content);
393 |
394 | snackbar = Snackbar.make(rootView,
395 | snackBarMessage,
396 | Snackbar.LENGTH_INDEFINITE);
397 |
398 | snackbar.setAction(snackBarAction, new View.OnClickListener() {
399 | @Override
400 | public void onClick(View view) {
401 | // Triggers the completion of the update of the app for the flexible flow.
402 | appUpdateManager.completeUpdate();
403 | }
404 | });
405 | }
406 |
407 | private void unregisterListener() {
408 | if (appUpdateManager != null && installStateUpdatedListener != null)
409 | appUpdateManager.unregisterListener(installStateUpdatedListener);
410 | }
411 |
412 | private void reportUpdateError(int errorCode, Throwable error) {
413 | if (handler != null) {
414 | handler.onInAppUpdateError(errorCode, error);
415 | }
416 | }
417 |
418 | private void reportStatus() {
419 | if (handler != null) {
420 | handler.onInAppUpdateStatus(inAppUpdateStatus);
421 | }
422 | }
423 |
424 | //endregion
425 | }
426 |
--------------------------------------------------------------------------------