0
点赞
收藏
分享

微信扫一扫

版本更新



<?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

 download Intent 假设 存在


 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 

举报

相关推荐

0 条评论