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.