|
Android example source code file (UpdateChecker.java)
The UpdateChecker.java Android example source code
package com.google.clickin2dabeat;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
/**
* Checks for updates to the game.
*/
public class UpdateChecker {
public String marketId;
@SuppressWarnings("finally")
public int getLatestVersionCode() {
int version = 0;
try {
URLConnection cn;
URL url =
new URL(
"http://apps-for-android.googlecode.com/svn/trunk/CLiCkin2DaBeaT/AndroidManifest.xml");
cn = url.openConnection();
cn.connect();
InputStream stream = cn.getInputStream();
DocumentBuilder docBuild = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document manifestDoc = docBuild.parse(stream);
NodeList manifestNodeList = manifestDoc.getElementsByTagName("manifest");
String versionStr =
manifestNodeList.item(0).getAttributes().getNamedItem("android:versionCode")
.getNodeValue();
version = Integer.parseInt(versionStr);
NodeList clcNodeList = manifestDoc.getElementsByTagName("clc");
marketId = clcNodeList.item(0).getAttributes().getNamedItem("marketId").getNodeValue();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FactoryConfigurationError e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
return version;
}
}
public void checkForNewerVersion(int currentVersion) {
int latestVersion = getLatestVersionCode();
if (latestVersion > currentVersion) {
}
}
}
Other Android examples (source code examples)Here is a short list of links related to this Android UpdateChecker.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.