Reputation: 8145
I want my Android app to check for update so I hosted a simple HTML page with this code:
<html>
<body>2.3</body> // Latest version
</html>
So I would get the version in the Body and compare it to the current version that is in the phone.
How do I get that number from a web page?
Upvotes: 0
Views: 3802
Reputation: 13327
URL url = new URL("http://url for your webpage");
URLConnection yc = url.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;
StringBuilder builder = new StringBuilder();
while ((inputLine = in.readLine()) != null)
builder.append(inputLine.trim());
in.close();
String htmlPage = builder.toString();
String versionNumber = htmlPage.replaceAll("\\<.*?>","");
NOTE: this will work only if your webpage contains html element like you put above , but it doesnot work if there is an entity element like &
in your html page .
Upvotes: 0
Reputation: 725
Android has left the net, io and nio.
Try the Java.net.URLConnection: http://docs.oracle.com/javase/tutorial/networking/urls/readingWriting.html
Upvotes: 1