URL="https://sharechain.qq.com/e568128f6e54ac8acf8feade92984606"--你的远端数据的地址 Http.get(URL,function(code,cont) if code ~= 200then--如果服务器返回数据异常,` print("服务器失联") activity.finish() end --cont就是服务器返回的数据,之后所有的代码都写在这里 --local用来声明局部变量,及这里的所以东西对你的其他代码的都没有任何影响。 local PackageName=this.getPackageName()--包名 local PackInfo=this.getPackageManager().getPackageInfo(PackageName,64)--包信息 local 本地版本=tonumber(PackInfo.versionCode)--版本号,这是我们要用的 --由于之后需要进行判断,因此此处使用tonumber()方法转换为数字 local 远端版本=cont:match("【版本】(.-)【版本】") local 下载地址=cont:match("【下载】(.-)【下载】") iftonumber(远端版本)>本地版本 then --提示检测更新 import "android.content.Intent" import "android.net.Uri" local viewIntent = Intent("android.intent.action.VIEW",Uri.parse(下载地址)) activity.startActivity(viewIntent) --顺带提醒下用户,免得他们一脸懵逼 print("请在打开的页面中下载更新并安装~") --当然如果你想强制更新的话,可以把下面这一行加上 activity.finish() --结束程序 end end)
gggxbbb commented1 week ago
测试
The above comments are provided by comment.js with the help of Github issue.
去评论