Solved - Check for update within android application not on Google Play -
i'm pretty new android coding, i'm sorry if make mistakes while asking question. i'm trying implement in-app updates personal use application , not put on play store. i've searched way through stack , found various methods through can achieved. tried own. thing is, doesn't work sometimes, , shows wrong information update being available. more specific, when compare curversioncode newversioncode, curversioncode = newversioncode, still shows newer version available.
here's activity -
public class test extends activity { private handler mhandler; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.front); mhandler = new handler(); checkupdate.start(); } } /* thread checks updates in background */ private thread checkupdate = new thread() { public void run() { try { url updateurl = new url("url txt file"); bufferedreader in = new bufferedreader(new inputstreamreader(updateurl.openstream())); string str; while ((str = in.readline()) != null) { // str 1 line of text; readline() strips newline character(s) /* current version number */ packageinfo packageinfo = getpackagemanager().getpackageinfo(getpackagename(), 0); int curversion = packageinfo.versioncode; int newversion = integer.valueof(str); /* higher version current out? */ if (newversion > curversion) { /* post handler ui pick , open dialog */ mhandler.post(showupdate); } } in.close(); } catch (exception e) { } } }; /* runnable creates dialog , asks user open update link*/ private runnable showupdate = new runnable(){ public void run(){ new alertdialog.builder(browseractivity.this) .seticon(r.drawable.ic_launcher) .settitle("update available") .setmessage("an update available!\n\nopen update page , see details?") .setpositivebutton("yes", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { /* user clicked ok stuff */ intent intent = new intent(intent.action_view, uri.parse("url update file")); startactivity(intent); } }) .setnegativebutton("no", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { /* user clicked cancel */ } }) .show(); } }; been searching few days, still ain't able find answer. i'm sorry if basic question i'm pretty new it.
thanks.
edit : code works fine. turns out requires time refresh version code on internet text file. doesn't matter, got experience.
Comments
Post a Comment