H5 + app, automatic updates are automatically deleted after installation package H5 + app - Automatic Updates

H5 + app automatically delete the installation package

I. Introduction

  Before doing the app automatically updates, a legacy of the problem, that is, after the installation package does not automatically update itself removed.

  Now it seems the phone system is the installation of automatic cleaning installation package. I think this H5 + after the installation of the app is not automatically deleted, so you need to use the code to be deleted.

Second, the solution

  Use html5 + plus, IO module to operate the auto-update legacy apk file.

  Reference documents:

    http://www.html5plus.org/doc/zh_cn/io.html

  IO modules: managing local file system, used to browse the directory of the file system, read files, write files and other operations. Available file system management objects through plus.io.

  Principle: 1, plus.io.requestFileSystem request by the local file system objects

           The first parameter type is PUBLIC_DOWNLOADS: Program constant public download directory

        After the successful return parameters fs, namely: all files in the directory of the download, and then traverse

        2, the file operation by plus.io.resolveLocalFileSystemURL

        The first argument that is the path name of the file, after the successful return parameter entry, namely: file object

        Get the file object can operate, view the file name, file size, delete, copy files, and so

Third, the code

  1, the following is the code to achieve

                plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, function(fs) {
                                // fs.root是根目录操作对象DirectoryEntry
                                var directoryReader = fs.root.createReader();
                                directoryReader.readEntries(function(entries) {
                                    for (var i = 0; i < entries.length; i++) {
                                        var fileName = entries[i].name;  var filePath = "_downloads/" + entries[i].name;
                                        plus.io.resolveLocalFileSystemURL(filePath, function(entry) {
                                             // can be operated by the object entry file test.html 
                                            // entry.file (function (File) { 
                                            //      the console.log (file.name); 
                                            // }); 
                                            entry.remove (); 
                                        }, function (E) {
                                             // the console.log ( "File Resolve failed the URL:" + e.message); 
                                        }); 
                                    } 
                                }, function (E) {
                                     // alert("Read entries failed: " + e.message);
                                });
                            });

  2, other practices

     Now there is a problem, that is installed after the restart is not controllable, so I'm the easiest way is to keep the most recent version of apk, other versions are deleted

     Of course there can be other practices that detect the need to update, if you do not update, delete program is started, the local installation clear.

function autoDeleteApk () { 
                plus.runtime.getProperty (plus.runtime.appid, function (INF) {
                     // Get app version information 
                    var Ver = inf.version;
                     // address of the interface, the server for acquiring the latest version number , compared with locally. 
                    var URL = '{your address interface}' ; 
                    mui.ajax (URL, { 
                        Data: { 
                            apkVersion: Ver, 
                        }, 
                        dataType: 'JSON' , 
                        type: 'the GET' , 
                        timeout: 60000 ,
                        success: function(data) {
                            var appVer = data.map.appVersion;
                            if (appVer == null) {
                                return;
                            }
                            plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, function(fs) {
                                // fs.root是根目录操作对象DirectoryEntry
                                var directoryReader = fs.root.createReader();
                                directoryReader.readEntries(function(entries) {
                                    for (var i = 0; i < entries.length; i++) {
                                        var fileName = entries[i].name;
                                        var appVerName = appVer + ".apk";
                                        if (fileName != appVerName) {
                                            console.log("不删除----------")
                                            return;
                                        }
                                        var filePath = "_downloads/" + entries[i].name;
                                        plus.io.resolveLocalFileSystemURL(filePath, function(entry) {
                                            // 可通过entry对象操作test.html文件 
                                            // entry.file(function(file) {
                                            //     console.log(file.name);
                                            // });
                                            entry.remove();
                                        }, function(e) {
                                            // console.log("Resolve file URL failed: " + e.message);
                                        });
                                    }
                                }, function(E) {
                                     //Alert ( "the Read entries It failed:" + e.message); 
                                }); 
                            }); 
                        }, 
                        error: function (XHR, type, errerThrown) {
                             // mui.toast ( 'network anomalies, please try again later') ; 
                        } 
                    }); 
                }); 
            }

IV Summary

  The remaining issues before finally resolved, before I do not know how, to go around themselves.

  Ambiguities can see another one: H5 + App - Automatic Updates

  Inadequate, please advise.

  Please indicate the source forwarding: https: //www.cnblogs.com/lrj1009IRET/

 

Guess you like

Origin www.cnblogs.com/lrj1009IRET/p/H5_App.html