• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

check latest versioncode

 
Mohsen Dehghani
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi .. my android app is currently hosted on a website similar to Playstore so that users can download.
the hosting website has offered instructions for developers who like to check the latest version of the app on server in order to for example inform the app user of an update. but I simply don't get it! the instructions don't seem very straight-forward to me.
I'll translate the instructions and hope that someone would simplify and explain how this thing exactly works:

add a package in your project and copy the following file in it: IUpdateCheckService.aidl
after that your project folders in Android Studio should look like this:

now you should build and compile your project.

suppose you want to ask the latest version code of your app from the host through an activity named UpdateCheckActivity .
for making a connection between the host and your own app make an inner class named UpdateServiceConnection which implements ServiceConnection .
UpdateServiceConnection includes the methods onServiceConnected and onServiceDiconnected .
these methods are callbacks that detect the stub of the hosting website when connected. here you need to change the type stub to Aidl (type cast).
the code below in the onServiceConnected method will provide access to the data and methods:

the complete code of UpdateCheckActivity is as follows:


the following class processes your request to the server and shows the answer by a toast.


when you want to examine the update status of the app you should initiate this service with initService(). in this example we have called the function inside the onCreate of the MainActivity.

the function initService makes a new UpdateServiceConnection and an Intent and connects both in order to get connected to the hosting website.

the function releaseService releases the resources of the users device.

when you are finished using this service you should call the function releaseService(). in this example we have called it within the function of onDestroy in the MainActivity.


the following line of the code above will return the latest version code of the app on the hosting site if it is newer than the version code of the app on the device. otherwise it will return -1. note that you should replace your own package name with the one given.










 
Tim Moores
Bartender
Posts: 3127
50
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The approach seems quite complicated, what with the service and all. Why not put a text file on your site that has a single line with the latest version? That would be easy to access via HTTP in the onCreate method.
 
Mohsen Dehghani
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:The approach seems quite complicated, what with the service and all. Why not put a text file on your site that has a single line with the latest version? That would be easy to access via HTTP in the onCreate method.

Thanks alot. that would be a great idea. the website also displays the latest version in the related app page like marked below:

is there a way to read that?

 
Tim Moores
Bartender
Posts: 3127
50
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An app could certainly read an HTTP page and extract some particular string from it, if the page doesn't change frequently. In a desktop app I'd use the HtmlUnit library for that; not sure if that works on Android.

It still seems easier to keep a simple text file on a web site you control.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic