From 00b8462cdec823c5b8c90656301825513bcbc2a8 Mon Sep 17 00:00:00 2001 From: Paolo Fabbri Date: Wed, 24 May 2017 16:02:02 +0100 Subject: [PATCH 1/2] remove autodownload --- README.md | 40 ++----------------------------------- plugin.xml | 22 ++++++++++---------- src/android/XAPKReader.java | 20 ------------------- 3 files changed, 12 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index a1a6daa..c2d314f 100644 --- a/README.md +++ b/README.md @@ -101,24 +101,6 @@ cordova plugin add https://github.com/agamemnus/cordova-plugin-xapkreader.git#co ## Plugin Config Variables -The plugin provides the following variables, which you can set in your app's `config.xml` file, or by adding the `--variable` flag (per variable, as above) to `cordova plugin add`. - -- **XAPK_PUBLIC_KEY (Required)**: The [Services & APIs public key][1] from your Google Play developer account. Google requires the app to provide this in order to download the expansion files from its servers. -- **XAPK_EXPANSION_AUTHORITY (Highly recommended)**: The [URI "authority"][2] string the plugin should use. This provides an easy way for you to access your expansion files' contents via URLs in the Cordova app. This name must be unique, so it's recommended to match your app's package name, or at least start with it, e.g. "org.example.mycordova" or "org.example.mycordova.expansion". **Any other app may access this data**: you can actually share data between apps that use the same url/expansion authority! - - *Default:* The package name of your app (e.g. the "id" attribute in your config.xml's "widget" tag). -- **XAPK_AUTO_DOWNLOAD**: Controls whether or not the plugin starts downloading automatically when the app launches. If true, the plugin will take over the app's UI with its downloader immediately upon launch, if files need to be downloaded. If false, your Cordova app will need to tell the plugin to initiate the Downloader. See [Compatibility with cordova-plugin-splashscreen](#Compatibility with cordova-plugin-splashscreen) -- **XAPK_PROGRESS_FORMAT**: Controls the formatting of the download progress dialogue. Recognized values are `percent` (show percentage downloaded) and `megabytes` (show number of megabytes downloaded, out of total). - - *Default:* `percent` -- *Text strings*: The following variables are text strings that are displayed to the user as part of the plugin's user interface. They're exposed as variables in case you want to translate or change them. - - **XAPK_TEXT_DL_ASSETS**: "Downloading assets..." - - **XAPK_TEXT_PR_ASSETS**: "Preparing assets..." - - **XAPK_TEXT_DL_FAILED**: "Download failed." - - **XAPK_TEXT_ERROR**: "Error." - - **XAPK_TEXT_CLOSE**: "Close." (as in close a window) - -There are a few others that in almost every case you don't need to worry about setting, as the defaults should be just fine: - -- **XAPK_MAIN_VERSION**: The [version number][3] for your "main" expansion file. - *Default:*: 0: Indicates that the app should use the first file it finds in the expansion directory that has a name starting with "main". (Google Play tries to ensure that you will never have more than one `main` and one `patch` file, so usually you don't need to worry about checking that their version numbers are correct.) - *If provided*: If not 0, the plugin will only use an expansion file with this version number. - **XAPK_MAIN_FILESIZE**: The size (in bytes) of your "main" expansion file. @@ -139,7 +121,7 @@ There are a few others that in almost every case you don't need to worry about s ## Expansion files (OBB files) -The expansion file should be a non-compressed ZIP file (also known as a "STOR" or "store"). That is, a ZIP file with 0% compression. Your ZIP file *can* include a directory structure, which can help to keep the files organized. +The expansion file should be a non-compressed ZIP file (also known as a "STOR" or "store"). That is, a ZIP file with 0% compression. Your ZIP file *can* include a directory structure, which can help to keep the files organized. In Ubuntu Linux, you can generate a non-compressed zip file by adding the `-0` flag to the standard CLI `zip` command. @@ -162,7 +144,7 @@ This plugin helps you to do that, by preferring files in `patch` over files in ` ## In Cordova Remember that expansion authority URI you set up in `XAPK_EXPANSION_AUTHORITY`? You can reference your expansion files from within your Cordova app, using an [Android Content URI][1] which includes your expansion authority string. - + ```html ``` @@ -191,24 +173,6 @@ Note that if your app is cross-platform (and that's a big part of Cordova's appe * If you upload a new main or patch APK expansion file to Google Play, the old main or patch file will be deleted when Google Play updates the user's device. - -# Compatibility with cordova-plugin-splashscreen -If you are using `cordova-plugin-splashscreen`, by default this plugin will prevent your splash screen from appearing on Android. This is because `cordova-plugin-splashscreen` is wired to automatically hide the splash screen after receiving a pause event. When this plugin activates the download activity, the pause event is fired, and the splash screen is hidden. - -To avoid this behavior, you'll want to set `XAPK_AUTO_DOWNLOAD` to `false` and invoke the plugin explicitly within your Javascript code by calling `XAPKReader.downloadExpansionIfAvailable`. Add the following in your javascript code at the earliest point where you know the splash page has been removed (either by explicitly hiding it or based on the timeout you set for the splashpage). - -```javascript - // XAPKReader will only be defined (and should only be invoked) for the Android platform - if (window.XAPKReader) { - window.XAPKReader.downloadExpansionIfAvailable(function () { - console.log("Expansion file check/download success."); - }, function (err) { - console.log(err); - throw "Failed to download expansion file."; - }) - } -``` - # License (for any non-Android SDK parts...) diff --git a/plugin.xml b/plugin.xml index 02f4b46..b530333 100644 --- a/plugin.xml +++ b/plugin.xml @@ -6,15 +6,15 @@ MIT (see readme.md) cordova,apk,expansion,file,xapk,expansion file reader,xapk reader,xapkreader,android,agamemnus,flyingsoftgames - + - + - + - + @@ -33,7 +33,6 @@ - @@ -49,10 +48,9 @@ $XAPK_PATCH_VERSION $XAPK_MAIN_FILESIZE $XAPK_PATCH_FILESIZE - $XAPK_AUTO_DOWNLOAD $XAPK_PROGRESS_FORMAT - + @@ -60,10 +58,10 @@ - + - + @@ -78,7 +76,7 @@ - + @@ -86,8 +84,8 @@ - + See the README.md file to complete your installation. - + diff --git a/src/android/XAPKReader.java b/src/android/XAPKReader.java index 1c3e9cb..b09eafa 100644 --- a/src/android/XAPKReader.java +++ b/src/android/XAPKReader.java @@ -50,7 +50,6 @@ public void initialize(final CordovaInterface cordova, CordovaWebView webView) { {"xapk_text_error", "string"}, {"xapk_text_close", "string"}, {"xapk_google_play_public_key", "string"}, - {"xapk_auto_download", "bool"}, {"xapk_progress_format", "string"} }; int curlen = xmlData.length; @@ -92,23 +91,11 @@ public void initialize(final CordovaInterface cordova, CordovaWebView webView) { ) { // We need the permission; so request it (asynchronously, callback is onRequestPermissionsResult) cordova.requestPermission(this, STARTUP_REQ_CODE, Manifest.permission.WRITE_EXTERNAL_STORAGE); - } else { - // We don't need the permission, or we already have it. - this.autodownloadIfNecessary(); } super.initialize(cordova, webView); } - public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException { - for (int r:grantResults) { - // They granted us WRITE_EXTERNAL_STORAGE (and thus, implicitly, READ_EXTERNAL_STORAGE) permission - if (requestCode == STARTUP_REQ_CODE && r == PackageManager.PERMISSION_GRANTED) { - this.autodownloadIfNecessary(); - } - } - } - @Override public boolean execute(final String action, final JSONArray args, final CallbackContext callContext) { try { @@ -136,13 +123,6 @@ public boolean execute(final String action, final JSONArray args, final Callback } } - private void autodownloadIfNecessary() { - boolean autoDownload = bundle.getBoolean("xapk_auto_download", true); - if (autoDownload) { - downloadExpansionIfAvailable(); - } - } - private void downloadExpansionIfAvailable() { cordova.getActivity().runOnUiThread(new Runnable() { @Override From 7fc25751f630fed185660cb64f4a1b2068dd0640 Mon Sep 17 00:00:00 2001 From: Paolo Fabbri Date: Fri, 26 May 2017 11:45:10 +0100 Subject: [PATCH 2/2] restore overdeleted section in README.md --- README.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c2d314f..c0a41f9 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ Table of Contents - [Testing](#testing) - [Cross-platform support](#Cross-platform-support) - [Tips](#tips) -- [Compatibility with cordova-plugin-splashscreen](#compatibility-with-cordova-plugin-splashscreen) - [License](#license) # Version @@ -101,6 +100,23 @@ cordova plugin add https://github.com/agamemnus/cordova-plugin-xapkreader.git#co ## Plugin Config Variables +The plugin provides the following variables, which you can set in your app's `config.xml` file, or by adding the `--variable` flag (per variable, as above) to `cordova plugin add`. + +- **XAPK_PUBLIC_KEY (Required)**: The [Services & APIs public key][1] from your Google Play developer account. Google requires the app to provide this in order to download the expansion files from its servers. +- **XAPK_EXPANSION_AUTHORITY (Highly recommended)**: The [URI "authority"][2] string the plugin should use. This provides an easy way for you to access your expansion files' contents via URLs in the Cordova app. This name must be unique, so it's recommended to match your app's package name, or at least start with it, e.g. "org.example.mycordova" or "org.example.mycordova.expansion". **Any other app may access this data**: you can actually share data between apps that use the same url/expansion authority! + - *Default:* The package name of your app (e.g. the "id" attribute in your config.xml's "widget" tag). +- **XAPK_PROGRESS_FORMAT**: Controls the formatting of the download progress dialogue. Recognized values are `percent` (show percentage downloaded) and `megabytes` (show number of megabytes downloaded, out of total). + - *Default:* `percent` +- *Text strings*: The following variables are text strings that are displayed to the user as part of the plugin's user interface. They're exposed as variables in case you want to translate or change them. + - **XAPK_TEXT_DL_ASSETS**: "Downloading assets..." + - **XAPK_TEXT_PR_ASSETS**: "Preparing assets..." + - **XAPK_TEXT_DL_FAILED**: "Download failed." + - **XAPK_TEXT_ERROR**: "Error." + - **XAPK_TEXT_CLOSE**: "Close." (as in close a window) + +There are a few others that in almost every case you don't need to worry about setting, as the defaults should be just fine: + +- **XAPK_MAIN_VERSION**: The [version number][3] for your "main" expansion file. - *Default:*: 0: Indicates that the app should use the first file it finds in the expansion directory that has a name starting with "main". (Google Play tries to ensure that you will never have more than one `main` and one `patch` file, so usually you don't need to worry about checking that their version numbers are correct.) - *If provided*: If not 0, the plugin will only use an expansion file with this version number. - **XAPK_MAIN_FILESIZE**: The size (in bytes) of your "main" expansion file. @@ -184,4 +200,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file