I am trying to develop android app; I need to check Is a higher version than the current already out -From play store- ?
I tried to write this code:
try {
URL updateURL = new URL("https://play.google.com/store/apps/details?id=com.XXXX.YYYY");
URLConnection conn = updateURL.openConnection();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while((current = bis.read()) != -1){
baf.append((byte)current);
}
/* Convert the Bytes read to a String. */
final String s = new String(baf.toByteArray());
/* Get current Version Number */
int curVersion = getPackageManager().getPackageInfo("com.XXXX.YYYY", 0).versionCode;
int newVersion = Integer.valueOf(s);
/* Is a higher version than the current already out? */
if (newVersion > curVersion) {
/* Post a Handler for the UI to pick up and open the Dialog */
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:com.XXXX.YYYY"));
startActivity(intent);
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.getStackTrace().toString(), Toast.LENGTH_LONG).show();
}
but error in this code is:
java.net.UnknownHostException: Unable to resolve host "play.google.com": No address associated with hostname
Unable to resolve host "play.google.com": No address associated with hostname