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小时开机,其他每个人都从这个“服务器”仓库克隆一份到自己的电脑上 ...
随机推荐
- PHP设置http头信息
<?PHP function https($num) { $http = array ( 100 => "HTTP/1.1 100 Continue", 101 =&g ...
- python快速搭建WebServer
#!/usr/bin/python import SimpleHTTPServer import SocketServer import os PORT = 7777 WEBDIR = "/ ...
- ajax创建对象
<script> function createAjax(){ var request=false; //window对象中有X ...
- Python 之socket的应用
本节主要讲解socket编程的有关知识点,顺便也会讲解一些其它的关联性知识: 一.概述(socket.socketserver): python对于socket编程,提供了两个模块,分别是socket ...
- Python中def的用法
def定义了一个模块的变量,或者说是类的变量.它本身是一个函数对象.属于对象的函数,就是对象的属性. def func(): return 2print func() # 1func = 5pr ...
- 像asp.net Mvc一样开发nodejs+express Mvc站点
像asp.net Mvc一样开发nodejs+express Mvc站点 首先,我是个c#码农.从事Mvc开发已然4个年头了,这两年前端MVC的兴起,我也跟风学了一些,对前端的框架也了解一些,angu ...
- jQuery插件之Form
一.jQuery.Form.js 插件的作用是实现Ajax提交表单. 方法: 1.formSerilize() 用于序列化表单中的数据,并将其自动整理成适合AJAX异步请求的URL地址格式. 2.cl ...
- hdu 3874 Necklace(bit树+事先对查询区间右端点排序)
Mery has a beautiful necklace. The necklace is made up of N magic balls. Each ball has a beautiful v ...
- Can you find it? 分类: 二分查找 2015-06-10 19:55 5人阅读 评论(0) 收藏
Description Give you three sequences of numbers A, B, C, then we give you a number X. Now you need t ...
- HDOJ-1012 u Calculate e(水)
http://acm.hdu.edu.cn/showproblem.php?pid=1012 简单套公式 # include <stdio.h> double Factorial(doub ...