package com.example.angluswang.mobilesafe.activity;

import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.TextView;

import com.example.angluswang.mobilesafe.R;

public class FlashActivity extends Activity {

    private TextView mTvVersion;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mTvVersion = (TextView) findViewById(R.id.tv_version);
        mTvVersion.setText("版本号： " + getVersionName());
    }

    /**
     * 获取版本号名
     * @return
     */
    private String getVersionName() {

        PackageManager packageManager = getPackageManager();
        try {
            // 获取包的信息
            PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), 0);

            int versionCode = packageInfo.versionCode;
            String versionName = packageInfo.versionName;

            System.out.println("versionName = " + versionName + "; versionCode = "
                    + versionCode);

            return versionName;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "";
    }
}

@@ -258,16 +258,228 @@
 esafe.R;
+%0Aimport com.example.angluswang.mobilesafe.utils.StreamUtils;%0A%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.net.HttpURLConnection;%0Aimport java.net.MalformedURLException;%0Aimport java.net.URL;
 %0A%0Apublic
@@ -835,16 +835,41 @@
 Name());
+%0A%0A        checkVersion();
 %0A    %7D%0A%0A
@@ -1478,24 +1478,24 @@
 %0A        %7D%0A%0A
-
         retu
@@ -1507,10 +1507,1337 @@
 ;%0A    %7D%0A
+    /**%0A     * %E4%BB%8E%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%8E%B7%E5%8F%96%E7%89%88%E6%9C%AC%E4%BF%A1%E6%81%AF%E8%BF%9B%E8%A1%8C%E6%A0%A1%E9%AA%8C%0A     */%0A    private void checkVersion() %7B%0A%0A        // %E5%90%AF%E5%8A%A8%E5%AD%90%E7%BA%BF%E7%A8%8B%E5%BC%82%E6%AD%A5%E5%8A%A0%E8%BD%BD%E6%95%B0%E6%8D%AE%0A        new Thread() %7B%0A%0A            @Override%0A            public void run() %7B%0A                URL url = null;%0A                HttpURLConnection conn = null;%0A                try %7B%0A                    //%E6%9C%AC%E5%9C%B0%E4%B8%BB%E6%9C%BA%E7%94%A8localhost%EF%BC%8C%E6%A8%A1%E6%8B%9F%E5%99%A8%E4%B8%8A%E5%8A%A0%E8%BD%BD%E6%9C%AC%E6%9C%BA%E7%9A%84%E5%9C%B0%E5%9D%80%EF%BC%8C%E7%94%A810.0.2.2%E6%9D%A5%E4%BB%A3%E6%9B%BF%0A                    url = new URL(%22http://10.0.2.2:8080/update.json%22);%0A                    conn = (HttpURLConnection) url.openConnection();%0A                    conn.setRequestMethod(%22GET%22);%0A                    conn.setConnectTimeout(5000);%0A                    conn.setReadTimeout(5000);%0A                    conn.connect();%0A%0A                    int responseCode = conn.getResponseCode();  //%E8%8E%B7%E5%8F%96%E5%93%8D%E5%BA%94%E7%A0%81%0A                    System.out.println(%22responseCode: %22 + responseCode);%0A                    if (responseCode == 200) %7B%0A                        InputStream in = conn.getInputStream();%0A                        String result = StreamUtils.ReadFromStream(in);%0A%0A                        System.out.println(%22%E7%BD%91%E7%BB%9C%E8%AF%B7%E6%B1%82%EF%BC%9A%22 + result);%0A%0A                    %7D%0A%0A                %7D catch (MalformedURLException e) %7B%0A%0A                    e.printStackTrace();%0A                %7D%0A                catch (IOException e) %7B%0A%0A                    e.printStackTrace();%0A                %7D%0A            %7D%0A        %7D.start();%0A    %7D%0A
 %7D%0A

添加checkVersion方法，用于从服务器获取版本信息进行校验（尚有问题）