Advertisement
LookedPath

Update.Java

Nov 4th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. package com.lookedpath.firstlesson;
  2.  
  3.  
  4.  
  5. import org.w3c.dom.Document;
  6. import org.w3c.dom.Element;
  7. import org.w3c.dom.NodeList;
  8.  
  9. import android.app.Activity;
  10. import android.os.AsyncTask;
  11. import android.os.Bundle;
  12. import android.view.View;
  13. import android.widget.TextView;
  14.  
  15.  
  16.    
  17.     public class Update extends Activity {
  18.         private TextView testo2;
  19.         @Override
  20.         public void onCreate(Bundle savedInstanceState) {
  21.             setContentView(R.layout.update);
  22.             super.onCreate(savedInstanceState);
  23.             testo2= (TextView) findViewById(R.id.textView2);
  24.            
  25.         }
  26.        
  27.  
  28.         public void goToUpdate (View v) {
  29.             new connection().execute();
  30.         }
  31.        
  32.         public class connection extends AsyncTask<Void, Void, Boolean> {
  33.            
  34.  
  35.  
  36.             protected Boolean doInBackground(Void...params) {
  37.                  boolean updated=false;
  38.                  final String URL = "http://www.lookedpath.tk/apps/firstapp/version.xml";
  39.                  final String VERSION = "version";
  40.                  XMLParser parser = new XMLParser();
  41.                  String xml = parser.getXmlFromUrl(URL); // getting XML
  42.                  Document doc = parser.getDomElement(xml); // getting DOM element
  43.          
  44.                  NodeList nl = doc.getElementsByTagName(VERSION);
  45.                  Element e = (Element) nl.item(0);
  46.                  String version = parser.getValue(e, VERSION); // name child value
  47.                  String actver = getString(R.string.version);
  48.                  if(actver==version){ updated=true;
  49.                  
  50.             }
  51.                  return updated;
  52.             }
  53.             protected void onPostExecute(Boolean updated) {
  54.                 if(updated==false){
  55.                     testo2.setText(R.string.newversion);
  56.                 } else {
  57.                         testo2.setText(R.string.nonewversion);
  58.                 }
  59.                
  60.             }
  61.            
  62.        
  63.            
  64.         }
  65.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement