How does Android realize automatic app update

Let's take a look at the renderings to be realized:

For Android users, it's no exaggeration to say that the mobile application market is flying all over the sky, such as Xiaomi, Meizu, Baidu, 360, Jifeng, APP treasure, etc. when we want to launch a new version of app, we don't mention the trouble of channel packaging. It simply means that the workload of uploading app to major application markets is already great. It's not easy for us to upload all apps, Suddenly found a small bug that would cause the application to flash back. At this time, it crashed. Obviously, it was not a big change. Do we have to upload and update the versions of major application markets again? Trust me, the operators will kill you!!

If there is a problem, there will naturally be a solution to the problem. Therefore, we will think that if the automatic update function is embedded in the app, we will save a lot of trouble. Of course, there are many third-party SDKs about this function.

Well, let's get down to business. Today we'll realize the automatic update of app by ourselves.

In fact, the process is not complicated: when the user opens the app, we ask the app to send a network request to check the version, or use the server to push a transparent message to the app to check the version of the app. If the current app version is older than that on the server, we remind the user to download and update the app. Of course, under specific circumstances, We can also force users to upgrade. Of course, this is very unfriendly. We can reduce such practices as much as possible.

OK, let's sort out the next process. First, since it is an app update, we need to download a new app, and then we need a notice to tell the user the current download progress. Then, when the app installation package is downloaded, we need to go to the system installation program to install and update the app.

Knowledge points:

Download: asynchronously request file download via HTTP and monitor the current download progress (I use okhttp here)

Notification: Notification (please refer to API documentation for specific usage)

Installation: intent (please refer to API documentation for specific usage)

Let's look at the specific implementation code:

We need a background service to support app download

Then we just need to call up this service when we want to update the app, such as "version check" in system settings

summary

Here, I just briefly demonstrate the function of automatically updating the app locally. In practical application, we should cooperate with the server. For example, when the user starts the app, compare the version number. If the version number is lower than the server version number, the server should give the client a transparent push. The push content here should be the download address of the new version of the app, At this time, you can download the new version of the app according to the address. When you encounter a major update and are no longer compatible with the old version, you can force the user to upgrade. There are many schemes here, such as calling the system level dialog box so that the user can't cancel and other operations. No more description is given here. The above is the whole content of this article. I hope it can be helpful to those in need.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>