cordova-plugin-in-app-updates 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ custom: ["https://www.paypal.com/ncp/payment/GEEM324PDD9NC"]
package/README.md CHANGED
@@ -2,9 +2,24 @@
2
2
 
3
3
  # cordova-plugin-in-app-updates
4
4
 
5
- Cordova Android plugin for checking for updates and auto updating app with Google Play Store In-App updates API.
6
-
7
- # Platforms
5
+ Cordova Android plugin for checking for updates and auto updating app with Google Play Store In-App updates API.
6
+
7
+ ## Table of contents
8
+
9
+ - [Platforms](#platforms)
10
+ - [Features](#features)
11
+ - [Installation](#installation)
12
+ - [Plugin versions](#plugin-versions)
13
+ - [Methods](#methods)
14
+ - [`getUpdateAvailability()`](#getupdateavailability)
15
+ - [`updateFlexible()`](#updateflexible)
16
+ - [`updateImmediate()`](#updateimmediate)
17
+ - [`setSnackbarOptions()`](#setsnackbaroptions)
18
+ - [Plugin demo app](#plugin-demo-app)
19
+ - [Contribute](#contribute)
20
+ - [Changelog](#changelog)
21
+
22
+ # Platforms
8
23
 
9
24
  - Android
10
25
  - Browser (filler platform)
@@ -15,8 +30,8 @@ Cordova Android plugin for checking for updates and auto updating app with Googl
15
30
  - Check for updates
16
31
  - Install flexible updates
17
32
  - Install immediate updates
18
- - Customize snackbar message and button for Flexible updates
19
- - Customize snackbar button color for Flexible updates
33
+ - Customize the completion dialog message and button for flexible updates
34
+ - Customize the completion dialog button color for flexible updates
20
35
 
21
36
  # Installation
22
37
 
@@ -28,6 +43,7 @@ Cordova Android plugin for checking for updates and auto updating app with Googl
28
43
  | 2.0.5 | 10.0.0 | 9.0.0 | Yes | 30/31 |
29
44
  | 2.1.0 | 10.0.0 | 11.0.0 | Yes | 32 |
30
45
  | 2.2.0 | 10.0.0 | 12.0.0 | Yes | 33 |
46
+ | 2.3.0 | 10.0.0 | 11.0.0 or later | Yes | 32 or later |
31
47
 
32
48
  ### Install latest version from NPM
33
49
 
@@ -94,7 +110,7 @@ cordova.plugins.InAppUpdate.updateFlexible(successCallback, errorCallback)
94
110
  - **RESULT_IN_APP_UPDATE_FAILED**: Something went wrong with the update dialog response.
95
111
  - **ACTIVITY_RESULT_UNKNOWN**: Unknown result code returned by the dialog.
96
112
  - **DOWNLOADING**: An update is currently being downloaded in the background.
97
- - **DOWNLOADED**: The update was downloaded and the snackbar with RESTART button has been shown.
113
+ - **DOWNLOADED**: The update was downloaded and the native completion dialog has been shown. Pressing its configured button calls `completeUpdate()`.
98
114
 
99
115
  :information_source: Browser platform does nothing and always returns **UPDATE_NOT_AVAILABLE**
100
116
 
@@ -149,10 +165,12 @@ cordova.plugins.InAppUpdate.updateImmediate(onSuccess, onFailure);
149
165
 
150
166
  ## setSnackbarOptions
151
167
 
152
- Sets the label and the button text for the snackbar shown after downloading a flexible update. You are free to call this method at any time. You can also call it again to show different snackbar messages after the snackbar was shown.
168
+ Configures the message, button text, and button color for the completion prompt shown after downloading a flexible update. Since version 2.3.0, this prompt is a native, non-cancelable Android `AlertDialog` instead of a Material Snackbar.
169
+
170
+ The public method name `setSnackbarOptions()` is preserved for compatibility with existing applications. Its arguments now configure the completion dialog. You may call it at any time, including again after a previous completion prompt was shown.
153
171
 
154
172
  ```javascript
155
- cordova.plugins.InAppUpdate.setSnackbarOptions(successCallback, errorCallback, snackbarText, snackbarButton, snackbarButtonColor)
173
+ cordova.plugins.InAppUpdate.setSnackbarOptions(successCallback, errorCallback, completionText, completionButton, completionButtonColor)
156
174
  ```
157
175
 
158
176
  :information_source: Browser platform does nothing and always returns **SUCCESS**
@@ -166,19 +184,19 @@ var onSuccess = function (strSuccess) {
166
184
  var onFailure = function (strError) {
167
185
  console.warn(strError);
168
186
  };
169
- var snackbarText = "An update has just been downloaded.";
170
- var snackbarButton = "RESTART";
171
- var snackbarButtonColor = "#76FF03";
172
- cordova.plugins.InAppUpdate.setSnackbarOptions(onSuccess, onFailure, snackbarText, snackbarButton, snackbarButtonColor);
187
+ var completionText = "An update has just been downloaded.";
188
+ var completionButton = "RESTART";
189
+ var completionButtonColor = "#76FF03";
190
+ cordova.plugins.InAppUpdate.setSnackbarOptions(onSuccess, onFailure, completionText, completionButton, completionButtonColor);
173
191
  ```
174
192
 
175
- ### Snackbar default values
193
+ ### Completion dialog default values
176
194
 
177
195
  If this method is not called, default messages in English will be shown as follows.
178
196
 
179
- - **snackbarText** = "An update has just been downloaded."
180
- - **snackbarButton** = "RESTART"
181
- - **snackbarText** = "#76FF03"
197
+ - **completionText** = "An update has just been downloaded."
198
+ - **completionButton** = "RESTART"
199
+ - **completionButtonColor** = "#76FF03"
182
200
 
183
201
  ### Return values
184
202
 
@@ -187,13 +205,38 @@ cordova.plugins.InAppUpdate.setSnackbarOptions(onSuccess, onFailure, snackbarTex
187
205
 
188
206
  # Plugin demo app
189
207
 
190
- - [Compiled APK and reference](https://www.andreszsogon.com/cordova-in-app-update-plugin-demo-app/) including testing procedure instructions
208
+ - [Plugin documentation wiki](https://github.com/andreszs/cordova-plugin-in-app-updates/wiki) with the current demo walkthrough, testing procedures, JavaScript usage, and troubleshooting
191
209
  - [Latest demo app version in Play Store](https://play.google.com/store/apps/details?id=com.andreszs.inappupdate.demo)
192
210
  - [Source code for www folder](https://github.com/andreszs/cordova-plugin-demos)
193
211
 
194
- <img src="https://github.com/andreszs/cordova-plugin-demos/blob/main/com.andreszs.inappupdate.demo/screenshots/cordova.in_app_updates_1.jpg?raw=true" width="200" /> <img src="https://github.com/andreszs/cordova-plugin-demos/blob/main/com.andreszs.inappupdate.demo/screenshots/cordova.in_app_updates_2.jpg?raw=true" width="200" /> <img src="https://github.com/andreszs/cordova-plugin-demos/blob/main/com.andreszs.inappupdate.demo/screenshots/cordova.in_app_updates_3.jpg?raw=true" width="200" /> <img src="https://github.com/andreszs/cordova-plugin-demos/blob/main/com.andreszs.inappupdate.demo/screenshots/cordova.in_app_updates_4.jpg?raw=true" width="200" />
195
-
196
- # Changelog
212
+ The screenshots below show an end-to-end flexible update using plugin 2.3.0. Version 1.4.1 of the demo was installed from Google Play, version 1.4.2 was offered as an update, and accepting the native completion dialog installed and relaunched the updated app.
213
+
214
+ | Demo and configuration | Update availability | Google Play flexible prompt |
215
+ | --- | --- | --- |
216
+ | <img src="assets/screenshots/cordova.in_app_updates_7_main_2.3.0.png" width="200" alt="In-App Update demo using plugin 2.3.0" /> | <img src="assets/screenshots/cordova.in_app_updates_10_update_available_2.3.0.png" width="200" alt="UPDATE_AVAILABLE result" /> | <img src="assets/screenshots/cordova.in_app_updates_11_flexible_prompt_2.3.0.png" width="200" alt="Google Play flexible update prompt" /> |
217
+ | Completion dialog options | Native completion dialog | Updated demo app |
218
+ | <img src="assets/screenshots/cordova.in_app_updates_8_completion_options_2.3.0.png" width="200" alt="Completion dialog options configured through setSnackbarOptions" /> | <img src="assets/screenshots/cordova.in_app_updates_13_native_completion_dialog_2.3.0.png" width="200" alt="Native non-cancelable completion AlertDialog" /> | <img src="assets/screenshots/cordova.in_app_updates_14_updated_1.4.2_plugin_2.3.0.png" width="200" alt="Demo updated to version 1.4.2 using plugin 2.3.0" /> |
219
+
220
+ The legacy `setSnackbarOptions()` method configures the message, button text, and button color shown in the native completion dialog. Pressing the configured button calls `completeUpdate()`.
221
+
222
+ # Contribute
223
+
224
+ Contributions are always welcome! If you find a bug or have an improvement in mind, please [open an issue](https://github.com/andreszs/cordova-plugin-in-app-updates/issues) or [submit a pull request](https://github.com/andreszs/cordova-plugin-in-app-updates/pulls). Every bit of feedback helps keep the plugin useful and reliable.
225
+
226
+ 💙 If this plugin saves you time, you can also support its continued development and maintenance through PayPal.
227
+
228
+ [Support the project via PayPal](https://www.paypal.com/ncp/payment/GEEM324PDD9NC)
229
+
230
+ ⭐ If financial support is not an option, [star this repository](https://github.com/andreszs/cordova-plugin-in-app-updates) or share it with other Cordova developers—both make a difference.
231
+
232
+ # Changelog
233
+
234
+ ### 2.3.0
235
+
236
+ - Replaced the Material Snackbar used after a flexible update download with a native Android `AlertDialog`.
237
+ - Removed the explicit Material Components and AppCompat dependencies.
238
+ - Preserved the existing JavaScript `setSnackbarOptions()` API; its values now configure the completion dialog.
239
+ - Restored compatibility with cordova-android 11 or later.
197
240
 
198
241
  ### 2.2.0
199
242
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-in-app-updates",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "In-App updates from Play Store for your Apache Cordova app.",
5
5
  "cordova": {
6
6
  "id": "cordova-plugin-in-app-update",
@@ -11,6 +11,10 @@
11
11
  },
12
12
  "engines": {
13
13
  "cordovaDependencies": {
14
+ "2.3.0": {
15
+ "cordova": ">=10.0.0",
16
+ "cordova-android": ">=11.0.0"
17
+ },
14
18
  "2.2.0": {
15
19
  "cordova": ">=10.0.0",
16
20
  "cordova-android": ">=12.0.0"
package/plugin.xml CHANGED
@@ -1,5 +1,5 @@
1
1
  <?xml version='1.0' encoding='utf-8'?>
2
- <plugin id="cordova-plugin-in-app-updates" version="2.2.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <plugin id="cordova-plugin-in-app-updates" version="2.3.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
3
3
  <name>InAppUpdate</name>
4
4
  <description>In-App updates from Play Store for your Apache Cordova app.</description>
5
5
  <license>MIT</license>
@@ -7,7 +7,7 @@
7
7
 
8
8
  <engines>
9
9
  <engine name="cordova" version=">=10.0.0" />
10
- <engine name="cordova-android" version=">=12.0.0" />
10
+ <engine name="cordova-android" version=">=11.0.0" />
11
11
  </engines>
12
12
 
13
13
  <js-module name="InAppUpdate" src="www/InAppUpdate.js">
@@ -19,15 +19,9 @@
19
19
  <preference name="AndroidXEnabled" value="true" />
20
20
  </config-file>
21
21
 
22
- <preference name="ANDROIDX_APPCOMPAT_VERSION" default="1.6.1" />
23
- <framework src="androidx.appcompat:appcompat:$ANDROIDX_APPCOMPAT_VERSION" />
24
-
25
22
  <preference name="ANDROID_PLAY_APP_UPDATE_VERSION" default="2.1.0" />
26
23
  <framework src="com.google.android.play:app-update:$ANDROID_PLAY_APP_UPDATE_VERSION" />
27
24
 
28
- <preference name="ANDROID_MATERIAL_VERSION" default="1.8.0" />
29
- <framework src="com.google.android.material:material:$ANDROID_MATERIAL_VERSION" />
30
-
31
25
  <config-file target="res/xml/config.xml" parent="/*">
32
26
  <feature name="InAppUpdate">
33
27
  <param name="android-package" value="com.andreszs.inappupdate.InAppUpdate" />
@@ -47,4 +41,4 @@
47
41
  <runs />
48
42
  </js-module>
49
43
  </platform>
50
- </plugin>
44
+ </plugin>
@@ -1,14 +1,10 @@
1
1
  package com.andreszs.inappupdate;
2
2
 
3
3
  import android.app.Activity;
4
+ import android.app.AlertDialog;
4
5
  import android.content.Intent;
5
- import android.content.IntentSender;
6
6
  import android.graphics.Color;
7
- import com.google.android.material.snackbar.Snackbar;
8
7
  import android.util.Log;
9
- import android.view.View;
10
- import android.widget.FrameLayout;
11
- import android.widget.TextView;
12
8
 
13
9
  import com.google.android.play.core.appupdate.AppUpdateInfo;
14
10
  import com.google.android.play.core.appupdate.AppUpdateManager;
@@ -22,9 +18,7 @@ import com.google.android.play.core.install.InstallStateUpdatedListener;
22
18
  import com.google.android.gms.tasks.Task;
23
19
 
24
20
  import org.apache.cordova.CallbackContext;
25
- import org.apache.cordova.CordovaInterface;
26
21
  import org.apache.cordova.CordovaPlugin;
27
- import org.apache.cordova.CordovaWebView;
28
22
  import org.apache.cordova.PluginResult;
29
23
 
30
24
  import org.json.JSONArray;
@@ -38,35 +32,26 @@ import static com.google.android.play.core.install.model.ActivityResult.RESULT_I
38
32
  public class InAppUpdate extends CordovaPlugin {
39
33
 
40
34
  private static String LOG_TAG;
41
- private static boolean PROMPTED = false;
42
35
  private static int currentUpdateType;
43
36
  private static AppUpdateManager appUpdateManager;
44
37
 
45
38
  private final int activityResultRequestCode = 777;
46
39
  private CordovaPlugin activityResultCallback;
47
- private FrameLayout layout;
48
- private Snackbar snackbar;
40
+ private AlertDialog completionDialog;
49
41
  private CallbackContext callbackContext;
50
42
 
51
- private String snackbarText = "An update has just been downloaded.";
52
- private String snackbarButton = "RESTART";
53
- private String snackbarButtonColor = "#76FF03";
43
+ private String completionPromptText = "An update has just been downloaded.";
44
+ private String completionPromptButton = "RESTART";
45
+ private String completionPromptButtonColor = "#76FF03";
54
46
 
55
47
  public InAppUpdate() {
56
48
  this.LOG_TAG = InAppUpdate.class.getSimpleName();
57
49
  Log.i(LOG_TAG, "Constructed");
58
50
  }
59
51
 
60
- @Override
61
- public void initialize(CordovaInterface cordova, CordovaWebView webView) {
62
- super.initialize(cordova, webView);
63
- layout = (FrameLayout) webView.getView().getParent();
64
- }
65
-
66
52
  @Override
67
53
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
68
54
  this.callbackContext = callbackContext;
69
- this.PROMPTED = false;
70
55
 
71
56
  Log.i(LOG_TAG, String.format("Executing the %s action started", action));
72
57
  if (action.equals("getUpdateAvailability")) {
@@ -144,24 +129,52 @@ public class InAppUpdate extends CordovaPlugin {
144
129
  this.activityResultCallback = plugin;
145
130
  }
146
131
 
147
- private void popupSnackbarForCompleteUpdate() {
148
- Log.i(LOG_TAG, "popupSnackbarForCompleteUpdate");
149
- this.PROMPTED = true;
132
+ private void showCompletionDialog() {
133
+ Log.i(LOG_TAG, "showCompletionDialog");
150
134
 
151
- cordova.getActivity().runOnUiThread(new Runnable() {
135
+ final Activity activity = cordova.getActivity();
136
+ if (activity == null) {
137
+ Log.w(LOG_TAG, "Unable to show completion dialog because the activity is unavailable");
138
+ return;
139
+ }
140
+
141
+ activity.runOnUiThread(new Runnable() {
152
142
  public void run() {
153
143
  try {
154
- snackbar = Snackbar.make(layout, snackbarText, Snackbar.LENGTH_INDEFINITE);
155
- snackbar.setAction(snackbarButton, new View.OnClickListener() {
156
- public void onClick(View view) {
157
- appUpdateManager.completeUpdate();
144
+ if (completionDialog != null) {
145
+ Log.i(LOG_TAG, "Completion dialog is already being shown");
146
+ return;
147
+ }
148
+
149
+ if (activity.isFinishing() || activity.isDestroyed()) {
150
+ Log.w(LOG_TAG, "Unable to show completion dialog because the activity is unavailable");
151
+ return;
152
+ }
153
+
154
+ final AlertDialog dialog = new AlertDialog.Builder(activity)
155
+ .setMessage(completionPromptText)
156
+ .setCancelable(false)
157
+ .setPositiveButton(completionPromptButton, (dialogInterface, which) -> {
158
+ if (appUpdateManager != null) {
159
+ appUpdateManager.completeUpdate();
160
+ }
161
+ })
162
+ .create();
163
+
164
+ dialog.setCanceledOnTouchOutside(false);
165
+ dialog.setOnShowListener(dialogInterface -> dialog.getButton(AlertDialog.BUTTON_POSITIVE)
166
+ .setTextColor(Color.parseColor(completionPromptButtonColor)));
167
+ dialog.setOnDismissListener(dialogInterface -> {
168
+ if (completionDialog == dialog) {
169
+ completionDialog = null;
158
170
  }
159
171
  });
160
- snackbar.setActionTextColor(Color.parseColor(snackbarButtonColor));
161
- snackbar.show();
172
+ completionDialog = dialog;
173
+ dialog.show();
162
174
  } catch (Exception e) {
163
175
  e.printStackTrace();
164
176
  Log.e(LOG_TAG, e.getMessage());
177
+ completionDialog = null;
165
178
  }
166
179
  }
167
180
  });
@@ -176,11 +189,11 @@ public class InAppUpdate extends CordovaPlugin {
176
189
  try {
177
190
 
178
191
  JSONObject arg_object = args.getJSONObject(0);
179
- this.snackbarText = arg_object.getString("strText");
180
- this.snackbarButton = arg_object.getString("strButton");
192
+ this.completionPromptText = arg_object.getString("strText");
193
+ this.completionPromptButton = arg_object.getString("strButton");
181
194
  String colorHex = arg_object.getString("strButtonColor");
182
- if (colorHex != null && colorHex.length() == 7) {
183
- this.snackbarButtonColor = colorHex;
195
+ if (colorHex != null && colorHex.length() == 7 && isValidColor(colorHex)) {
196
+ this.completionPromptButtonColor = colorHex;
184
197
  result = new PluginResult(PluginResult.Status.OK, "SUCCESS");
185
198
  } else {
186
199
  result = new PluginResult(PluginResult.Status.OK, "SUCCESS (Invalid HEX color specified; ignored)");
@@ -197,6 +210,15 @@ public class InAppUpdate extends CordovaPlugin {
197
210
 
198
211
  }
199
212
 
213
+ private boolean isValidColor(String colorHex) {
214
+ try {
215
+ Color.parseColor(colorHex);
216
+ return true;
217
+ } catch (IllegalArgumentException e) {
218
+ return false;
219
+ }
220
+ }
221
+
200
222
  private void updateFlexible() {
201
223
 
202
224
  currentUpdateType = AppUpdateType.FLEXIBLE;
@@ -225,12 +247,9 @@ public class InAppUpdate extends CordovaPlugin {
225
247
  // Unregister listener
226
248
  appUpdateManager.unregisterListener(installStateUpdatedListener);
227
249
 
228
- // Prevent multiple consecutive prompts of this event
229
- if (!PROMPTED) {
230
- popupSnackbarForCompleteUpdate();
231
- PluginResult result = new PluginResult(PluginResult.Status.OK, "DOWNLOADED");
232
- callbackContext.sendPluginResult(result);
233
- }
250
+ showCompletionDialog();
251
+ PluginResult result = new PluginResult(PluginResult.Status.OK, "DOWNLOADED");
252
+ callbackContext.sendPluginResult(result);
234
253
  } else if (state.installStatus() == InstallStatus.INSTALLED) {
235
254
  // Update installed.
236
255
  Log.i(LOG_TAG, "InstallStateUpdatedListener: InstallStatus.INSTALLED");
@@ -265,7 +284,7 @@ public class InAppUpdate extends CordovaPlugin {
265
284
  // When status updates are no longer needed, unregister the listener.
266
285
  appUpdateManager.unregisterListener(installStateUpdatedListener);
267
286
 
268
- popupSnackbarForCompleteUpdate();
287
+ showCompletionDialog();
269
288
  PluginResult result = new PluginResult(PluginResult.Status.OK, "DOWNLOADED");
270
289
  callbackContext.sendPluginResult(result);
271
290
 
@@ -435,8 +454,8 @@ public class InAppUpdate extends CordovaPlugin {
435
454
  if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) {
436
455
  // If the update is downloaded but not installed, notify the user to complete the update.
437
456
  if (currentUpdateType == AppUpdateType.FLEXIBLE) {
438
- Log.i(LOG_TAG, "onResume: popupSnackbarForCompleteUpdate");
439
- popupSnackbarForCompleteUpdate();
457
+ Log.i(LOG_TAG, "onResume: showCompletionDialog");
458
+ showCompletionDialog();
440
459
  } else {
441
460
  Log.i(LOG_TAG, "onResume: startUpdate");
442
461
  try {
@@ -472,4 +491,14 @@ public class InAppUpdate extends CordovaPlugin {
472
491
 
473
492
  }
474
493
 
494
+ @Override
495
+ public void onDestroy() {
496
+ if (completionDialog != null) {
497
+ completionDialog.setOnDismissListener(null);
498
+ completionDialog.dismiss();
499
+ completionDialog = null;
500
+ }
501
+ super.onDestroy();
502
+ }
503
+
475
504
  }
@@ -1,4 +0,0 @@
1
- file.reference.cordova-plugin-in-app-update-www=www
2
- files.encoding=UTF-8
3
- site.root.folder=${file.reference.cordova-plugin-in-app-update-www}
4
- source.folder=
@@ -1,9 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project xmlns="http://www.netbeans.org/ns/project/1">
3
- <type>org.netbeans.modules.web.clientproject</type>
4
- <configuration>
5
- <data xmlns="http://www.netbeans.org/ns/clientside-project/1">
6
- <name>cordova-plugin-in-app-update</name>
7
- </data>
8
- </configuration>
9
- </project>