티스토리 툴바



안드로이드에서 버전업 했을때 버전 확인하고 다운 받기

public boolean CertificateVersion()
{
        String s_url = "버전이 있는 주소";
        URL ver_url;
try {
ver_url = new URL(s_url);

   HttpURLConnection http;
try {
http = (HttpURLConnection)ver_url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(http.getInputStream()));
        StringBuffer buffer = new StringBuffer();
       
        int c;
        while((c=in.read()) != -1){
        buffer.append((char)c);  
        }
        String content = buffer.toString();//content 있는 값을 비교한다.
if(content.equals(version) == false)
{
Update(); 
}
       
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return false;
}


public void Update()
{
File updater = new File("/sdcard/프로그램업데이터넣을곳/");

if(!updater.exists()) {
updater.mkdirs();
}
try {
    URLConnection uc = new URL(업데이트 주소).openConnection();
    InputStream in = uc.getInputStream();
   
    int len=0;
    byte[] buf = new byte[1024];
       
     File updateFile=new File(updater + filename);

       // 다운로드
     FileOutputStream fos = new FileOutputStream(updateFile);

       while((len=in.read(buf, 0, 1024)) != -1) {
        total += len;
        fos.write(buf, 0, len);
      }
      in.close();
      fos.flush();
      fos.close();
     } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      Log.i("fdin", e.getMessage());
     }
Toast.makeText(Activity.this, "업데이트 파일을 실행해주세요, 위치 : " + updater + filename, Toast.LENGTH_LONG).show();
 
System.exit(0);
Comment 0 Trackback 0

Trackback : http://fdin.tistory.com/trackback/39 관련글 쓰기

Top

prev 1 ... 2 3 4 5 6 7 8 9 10 ... 38 next