版本更新
16lz
2021-01-23
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.yourcompany.yourapp" android:versionCode="109" android:versionName="0.1.6.109 dev"> ...</manifest>
public static int getVersionCode(Context context) { PackageManager pm = context.getPackageManager(); try { PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); return pi.versionCode; } catch (NameNotFoundException ex) {} return 0;}
public static int getVersionCode(Context context) { PackageManager pm = context.getPackageManager(); try { PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); return pi.versionName; } catch (NameNotFoundException ex) {} return 0;}
- The APK: http://some-public-url/deploy/MyApplication.apk
- The version info file: http://some-public-url/deploy/versioninfo.txt
HTTP connection and issuing a GET request:
private String downloadText() { int BUFFER_SIZE = 2000; InputStream in = null; try { in = openHttpConnection(); } catch (IOException e1) { return ""; } String str = ""; if (in != null) { InputStreamReader isr = new InputStreamReader(in); int charRead; char[] inputBuffer = new char[BUFFER_SIZE]; try { while ((charRead = isr.read(inputBuffer)) > 0) { // ---convert the chars to a String--- String readString = String.copyValueOf(inputBuffer, 0, charRead); str += readString; inputBuffer = new char[BUFFER_SIZE]; } in.close(); } catch (IOException e) { return ""; } } return str;}
首先比较版本是不是比以前的高 如果高就下载apk
Intent updateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://some-public-url/deploy/MyApplication.apk"));startActivity(updateIntent);
上面只是简单的实现,最好下载apk放到sd卡然后安装 以及删掉原来的apk
更多相关文章
- Ubuntu 12.04 Desktop 版本编译 Android 4.0.4 出错解决
- Android 后台保活设计2019,最新版本
- 【Android】获取apk的版本及包名等信息
- android 各版本新特性
- Android依赖库版本不一致
- appcompat-v7 版本造成的问题No resource found that matches th
- Android Studio版本控制指南