// Path: app/src/main/java/com/yan/mobilesafe/utils/StreamUtils.java
// public class StreamUtils  {
// 
//     /**
//      * 转换成字符串
//      * **/
//     public static String readFromStream(InputStream stream) throws IOException {
//         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// 
//         int len = 0;
//         byte[] bytes = new byte[1024];
// 
//         while((len = stream.read(bytes))!= -1){
//             outputStream.write(bytes,0,len);
//         }
//         String result = outputStream.toString();
//         stream.close();
//         outputStream.close();
//         return result;
// 
//     }
// }


import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.yan.mobilesafe.R;
import com.yan.mobilesafe.utils.StreamUtils;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import android.os.Handler;
        } else {
            handler.sendEmptyMessageDelayed(CODE_NO_UP_UPDATE, 1000);
        }


    }

    /**
     * 从服务器获取版本信息进行校验
     */
    private void checkVersion() {

        final long startTime = System.currentTimeMillis();  //获取当前时间

        new Thread() {
            @Override
            public void run() {
                message = Message.obtain();
                HttpURLConnection connection = null;
                try {
                    URL url = new URL(UPDATEURL);
                    connection = (HttpURLConnection) url.openConnection();
                    connection.setRequestMethod("GET");//设置请求方法
                    connection.setConnectTimeout(5000); //设置连接超时
                    connection.setReadTimeout(5000); //设置响应超时
                    connection.connect(); //连接服务器

                    int responseCode = connection.getResponseCode(); //获得响应码
                    if (responseCode == 200) {
                        InputStream inputStream = connection.getInputStream();  //获取输入流
// Path: app/src/main/java/com/yan/mobilesafe/utils/StreamUtils.java
// public class StreamUtils  {
// 
//     /**
//      * 转换成字符串
//      * **/
//     public static String readFromStream(InputStream stream) throws IOException {
//         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// 
//         int len = 0;
//         byte[] bytes = new byte[1024];
// 
//         while((len = stream.read(bytes))!= -1){
//             outputStream.write(bytes,0,len);
//         }
//         String result = outputStream.toString();
//         stream.close();
//         outputStream.close();
//         return result;
// 
//     }
// }


// Path: app/src/main/java/com/yan/mobilesafe/activity/MainActivity.java
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.yan.mobilesafe.R;
import com.yan.mobilesafe.utils.StreamUtils;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import android.os.Handler;

        } else {
            handler.sendEmptyMessageDelayed(CODE_NO_UP_UPDATE, 1000);
        }


    }

    /**
     * 从服务器获取版本信息进行校验
     */
    private void checkVersion() {

        final long startTime = System.currentTimeMillis();  //获取当前时间

        new Thread() {
            @Override
            public void run() {
                message = Message.obtain();
                HttpURLConnection connection = null;
                try {
                    URL url = new URL(UPDATEURL);
                    connection = (HttpURLConnection) url.openConnection();
                    connection.setRequestMethod("GET");//设置请求方法
                    connection.setConnectTimeout(5000); //设置连接超时
                    connection.setReadTimeout(5000); //设置响应超时
                    connection.connect(); //连接服务器

                    int responseCode = connection.getResponseCode(); //获得响应码
                    if (responseCode == 200) {
                        InputStream inputStream = connection.getInputStream();  //获取输入流
                        String result = StreamUtils.readFromStream(inputStream); //把输入流转成字符串