Github获取仓库最新Release版本号API
package me.chunsheng.hongbao.utils; import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.widget.Toast; import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONObject; import me.chunsheng.hongbao.R; import java.io.ByteArrayOutputStream;
import java.io.IOException; /**
* Util for app update task.
*/
public class UpdateTask extends AsyncTask<String, String, String> {
private Context context;
private boolean isUpdateOnRelease;
//public static final String updateUrl = "https://api.github.com/repos/geeeeeeeeek/WeChatLuckyMoney/releases/latest";
public static final String updateUrl = "https://api.github.com/repos/geeeee/WeChatLuckyMoney/releases/latest"; public UpdateTask(Context context, boolean needUpdate) {
this.context = context;
this.isUpdateOnRelease = needUpdate;
if (this.isUpdateOnRelease) Toast.makeText(context, "正在检查新版本……", Toast.LENGTH_SHORT).show();
} @Override
protected String doInBackground(String... uri) {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
String responseString = null;
try {
response = httpclient.execute(new HttpGet(uri[]));
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() == ) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
responseString = out.toString();
out.close();
} else {
// Close the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (Exception e) {
return null;
}
return responseString;
} @Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
try {
JSONObject release = new JSONObject(result); // Get current version
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), );
String version = pInfo.versionName; String latestVersion = release.getString("tag_name");
boolean isPreRelease = release.getBoolean("prerelease");
if (!isPreRelease && version.compareToIgnoreCase(latestVersion) >= ) {
// Your version is ahead of or same as the latest.
if (this.isUpdateOnRelease)
Toast.makeText(context, R.string.update_already_latest, Toast.LENGTH_SHORT).show();
} else {
if (!isUpdateOnRelease) {
Toast.makeText(context, context.getString(R.string.update_new_seg1) + latestVersion + context.getString(R.string.update_new_seg3), Toast.LENGTH_LONG).show();
return;
}
// Need update.
String downloadUrl = release.getJSONArray("assets").getJSONObject().getString("browser_download_url"); // Give up on the fucking DownloadManager. The downloaded apk got renamed and unable to install. Fuck.
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(downloadUrl));
browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(browserIntent);
Toast.makeText(context, context.getString(R.string.update_new_seg1) + latestVersion + context.getString(R.string.update_new_seg2), Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
if (this.isUpdateOnRelease)
Toast.makeText(context, R.string.update_error, Toast.LENGTH_LONG).show();
}
} public void update() {
super.execute(updateUrl);
}
}
Github获取仓库最新Release版本号API的更多相关文章
- Github 获取仓库的releases API
API 文档 example: 这将获取所有的版本 https://api.github.com/repos/januwA/flutter_anime_app/releases 最新版本: https ...
- github 获取repo 发布的版本号
获取最新版本 https://api.github.com/repos/nickchou/paopao/releases/latest 获取版本列表 https://api.github.com/re ...
- git笔记之eclipse使用github远程仓库进行版本号管理
原文地址:http://dtbuluo.com/90.html 这里记录一下eclipse开发工具中git的使用说明. 环境:centOS.eclipse-jee-kepler-SR2-linux-g ...
- iOS开发——源代码管理——git(分布式版本控制和集中式版本控制对比,git和SVN对比,git常用指令,搭建GitHub远程仓库,搭建oschina远程仓库 )
一.git简介 什么是git? git是一款开源的分布式版本控制工具 在世界上所有的分布式版本控制工具中,git是最快.最简单.最流行的 git的起源 作者是Linux之父:Linus Bened ...
- maven snapshot和release版本号之间的差
在使用maven过程.我们经常会在不稳定的状态有很多公共图书馆在发展阶段.需要改变在任何时间和公布,你可能有一天一次发布.经验bug时间,甚至一天公布N次要.我们知道,.maven依赖管理是基于管理的 ...
- 使用命令创建github代码仓库,push本地仓库到github远程代码仓库
1.利用命令创建github远程代码仓库 在将本地代码push到github远程代码仓库之前,总是需要新建github代码仓库,在将本地仓库关联到github远程仓库.其中最为繁琐的操作是建立gith ...
- Android 获取当前应用的版本号和当前系统的版本号
1.获取当前程序版本名 我们可以在AndroidManifest.xml中设置程序的版本号等,如android:versionName="1.0",那如果想在代码中获取这个版本号呢 ...
- Tesseract 3.04 + VS2013 配置心得(包括静态库版本号和Release版本号)
研究Tesseract也有几个星期了 走了一些弯路 网上有非常多VS2010的配置心得 但没有VS2013的, 找到一篇之后, 又发现会有一些小问题, 这里记录下来, 也为新人提供一些帮助. Tess ...
- GitHub 远程仓库 de 第一次配置
GitHub远程仓库, Git是分布式版本控制系统,同一个Git仓库,可以分布到不同的机器上.首先找一台电脑充当服务器的角色, 每天24小时开机,其他每个人都从这个“服务器”仓库克隆一份到自己的电脑上 ...
随机推荐
- java zip工具类
依赖jar :apache-ant-1.9.2-bin.zip import java.io.File; import java.io.FileInputStream; import java.io. ...
- 做了一个js的拉动遮罩层,两个图片分别显示的效果
想做成车修好了和没修好的对比,所以需要两个图片.需要用到的知识点, 1.定位 2.mouse 的事件(代码中体现) 3.鼠标指针的移动距离算法 4.css中,cursor的应用 好了,废话不多说 ,直 ...
- Smallest Difference(POJ 2718)
Smallest Difference Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6740 Accepted: 18 ...
- Gnome快捷键
1.Gnome快捷键 http://wiki.ubuntu.org.cn/Gnome%E5%BF%AB%E6%8D%B7%E9%94%AE 2.
- stopWeblogic时提示错误以及无法关闭服务
执行: y@y:~/oracle/middleware/user_projects/domains/yshy_domain/bin$ ./stopWebLogic.sh 错误信息如下: Stoppin ...
- \s+(?<request_time>\d+(?:\.\d+)?)\s+ 解释
<pre name="code" class="html"><pre name="code" class="ht ...
- bzoj1622 [Usaco2008 Open]Word Power 名字的能量
Description 约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只奶牛的名字由不超过1000个字待构成,没有一个名字是空字体串, 约翰有一张“能量字符串表”,上面有M(1 ...
- UESTC_秋实大哥掰手指 2015 UESTC Training for Dynamic Programming<Problem B>
B - 秋实大哥掰手指 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 2048/1024KB (Java/Others) Submit ...
- UESTC_我要长高 CDOJ 594
韩父有N个儿子,分别是韩一,韩二…韩N.由于韩家演技功底深厚,加上他们间的密切配合,演出获得了巨大成功,票房甚至高达2000万.舟子是名很有威望的公知,可是他表面上两袖清风实则内心阴暗,看到韩家红红火 ...
- laravel5.3 笔记一
laravel5.3 笔记 安装环境 laravel环境,laravel中文学习论坛上面有相关的教程 创建应用 laravel new blog 其中blog就是你的应用的名字 数据迁移 php ar ...