Research and implementation of the high-speed download of Sogou market and the app page of Web page end

Source: Internet
Author: User
Tags chrome developer chrome developer tools



GitHub blog address, updates here may not be very timely.






Haven't written a blog for a long time, a good big hole. Just right, recently finished Sogou market of high-speed download function, then took to fill this pit.



Say products in order to increase user volume, enhance user activity and to cooperate with the promotion, more pit dad is to see other markets also have these features, and so on, asked to do a bundle download function. WTF.



Of course The Spit groove, the task is still to be completed.



The specific requirements are: Users in the mobile phone to browse the WAP site, 1. Enter the application Details page to open the application (Sogou market) inside the Details page 2. Click on the WAP-side high-speed download, if the app is installed, then call the app to download, otherwise download the app's bundle, after the installation is complete, when the app opens to download the app that the user wants to download. How do you implement these two functions? The following stepwise analysis:


1. Functional Requirements


As described earlier.



In general, the previous two functions are generally required to be installed and run in the background (the simplest understanding is that the app has opened the app and has not been killed by other programs), so this is also the case that the application is installed, otherwise, it is considered not installed (the following is not specifically described, this is the case).


2. Competitive Product Analysis


Of course, since the competing products have these features, then first take doctrine, study how they do it. Through the Chrome capture packet analysis, the final analysis is as follows.



Baidu Mobile Assistant http://127.0.0.1:6259/



Sogou Mobile Assistant http://127.0.0.1:12388/



Pea Pod Custom Protocol Wandoujia://detail/app/cn.buding.martin



Baidu mobile phone assistant and Sogou Mobile Phone helper program is basically the same, the use of access to a mobile phone local service address 127.0.0.1 (loopback address), the port address is different , the Pea pod uses a custom protocol that allows the browser to automatically distribute it to the activity that registered the Wandoujia protocol.



Open app Details This opens the browser's corresponding details page, Baidu mobile phone assistant and Sogou mobile phone assistant simultaneously access the local loopback address, and the pea pod calls the custom protocol by the system calls the related application (usually is the pea pod).



high-speed download principle pea pod is not implemented in the application has been installed in the context of calling the client to download, when clicking on the download, the query is to download the bundle or directly download the application you want to download (description of the text at the end of the drawings, the copy is inductive). Select Download bundle to download a pea pod installation package with a specific file name. After the installation is complete, go to scan a specific directory (typically download and the download directory of common browsers), if there is a rule-compliant file, then extract the relevant resource ID, and then download the bundled app later.


    1. In cases where the app is not installed. and Baidu mobile phone and Sogou mobile phone assistant Click High-Speed download (the name is also induced), then directly download an app, all app content, but the app name is different, are similar to APP_ bundle id_xx.apk, such as Sogou Mobile phone helper bundled for Mobiletools_ 8271386494777466339_71.APK, bundle IDs for bundling other packages are different. Other processes with pea pods. If there are more than one eligible apk, Sogou mobile phone assistant to take the latest information to download, Baidu mobile phone assistant did not study.
    2. If the phone app is already installed. Pea pod did not realize, and Baidu mobile phone assistant and Sogou mobile phone assistant, is the browser Web page directly request a loopback address (127.0.0.1:port/actionpath?parameter), port address, Baidu mobile phone assistant for 6259, Sogou mobile phone assistant for 12388. Actionpath is required for the operation, different operations, values are inconsistent parameter for the relevant operation parameters, here the need to bundle downloaded app data passed. The mobile app downloads the app via an in-app HTTP server, and returns the data accordingly.
3. The final programme


Adjust the details page , using the HTTP server and the custom protocol both can be, and the custom protocol does not have to run in the background a service that hosts an HTTP server will compare power savings.



Follow the high-speed download , pea pod is no, since the previous talk about the custom protocol power saving, can you consider it? Combined with the requirements, look, the application is not installed in the case, directly download the bundle, both have no problem, apply the installed situation, the client to download. Can a custom protocol be done? How do I know if an app is installed? Does the browser have a corresponding API? Obviously no, even if there is, it may only be part of it, but to support all browsers. The only way to do this is by accessing the HTTP server, setting the time-out, and not having a response within a certain time that the app is not installed and downloads the appropriate bundle. Moreover, through the subsequent extension of the HTTP server, you can interact with the Web via Web server, for example, Baidu Mobile Assistant can get location information through the Web. and the custom protocol is obviously not going to do that. Except, of course, save electricity.



High-speed download of the adjustment to solve, if the application is not installed, after the application installation is complete, how to know before users need to download which app? that is, the identification of the bundled application . Sogou Market The first solution is to enter a file in the application (asset folder), storing the ID number of the bundled app. However, for a small number of applications (initially used in order to test the bundle effect), currently, for a large number of applications must not, need to hit a large number of packages, and need a lot of storage space.



It is perfect to refer to competing items, however, considering that most of the current mobile security or cleanup software will prompt you to remove the installation package when the app is successfully installed, and the browser's download directory may change. Is it possible to scan the entire SD card here to find eligible files? Certainly not, too time-consuming.



How do you know the app ID of the bundle when the app is not installed or not running in the background? The above two programs are not perfect, how to solve. With the back-end Yan Fei discussed, in the high-speed download apk, the webpage records the mobile phone to download the bundle app ID and PackageName and the device's unique ID (UUID), and then open the market, request the appropriate interface and the UUID incoming, to obtain data, so as to download the appropriate application. Great idea, and later found no practical value, UUID temporarily does not have a reasonable plan. The point is that both ends are created to be unique, Mac,ip? How to generate?



After dinner with the country after the discussion, consider whether you can call the local code to perform related tasks? But after careful thinking, found that this is generally webview and JS to interact. And the current usage scenario simply can't be done. This webview has to be used within its own application.



Consider a number of factors, and finally decided to refer to Baidu mobile phone assistant and Sogou Mobile Phone helper program, despite the shortcomings. For the custom protocol mode, refer to this article,Android custom protocol and HTML loading automatically try to invoke the local app, as well as Android registration monitoring custom Protocol , this article does not do too much introduction.



The final solution is to run a httpserver through the service in the backend of the mobile phone, listening to Port 12307.


To tune up the client


1. High-Speed download



Access Http://127.0.0.1:12307/appdown?downid=1&packagename=com.sogou.map When you click on a high-speed download on the Web



If successful, returns the JSON string in the form of



{"Status": 1, "message": "OK"}



A status of 0 indicates a failure, and a status of 1 indicates success. Message for a specific description.



If the phone does not respond within a certain time, the default app is not installed, download bundle APK package.



If the phone side responds, then the web side does not do any processing, the phone side to obtain the corresponding Downid and PackageName, first determine whether the application has been installed, if installed, the application is installed, if not installed, prompts the user app is downloading, and then join the download list.



2. Open the Details page



When Http://127.0.0.1:12307/godetail?downid=1&packagename=com.sogou.map&backtohome=ture Backtohome is true, Press the Back button on the phone to go back to the app's home page, and return to the browser when false. (can refer to pea pods, for example (HTTP://WWW.WANDOUJIA.COM/APPS/COM.TENCENT.MM) [http://www.wandoujia.com/apps/com.tencent.mm] must be accessed on the phone, User-agent different from PC access)


Install package App Bundle


How do you identify which application is bundled?



Subsequent reference to the implementation of the competition, by downloading the file name of a different (file name has rules) files, after the user installs the application and open to read the download folder, to determine whether there is a rule-based apk. If it exists, extract the appropriate ID and go to the appropriate download. As long as the server provides an interface for the browser to download the same file displayed as a different filename.



For example Sogou Mobile Helper's a detailed address is http://wap.sogou.com/app/apkdetail.jsp?ppid=34 &cid=49&docid=8271386494777466339&e=1394 , the address of the high-speed download installation package is http:// download.zhushou.sogou.com/zhushou/android/mobiletools.apk?dn=mobiletools_8271386494777466339_71.apk The downloaded apk name is called mobiletools_8271386494777466339_71.apk. The app ID for the bundle is 8271386494777466339 and applies to. content-disposition attachment;filename= "mobiletools_8271386494777466339_71.apk"



As a result, it is determined that the APK is named sogouappmall_binding_downid_9.apk and that the application will extract Downid (Downid must be an integer) in this format (which can be matched by a regular match). When the app is not installed, click on the high-speed download to download the above rule-named apk to the folder. When the user installs the application and opens the application, to scan the common download folder (common/download,/downloads, as well as the browser download folder, etc.) inside the APK, has the rule to extract the ID of a file, after the extraction is completed, to download, Remove the installation package at the same time (prevent interference after). Consider that the same folder may have more than one rule-compliant installation package, the current folder according to the time order of the last two times the rule, the other folder is ignored, and so on the next start of processing (generally this is relatively small). There are, of course, other details that need to be dealt with and not detailed here.


4. Performance Optimization and Outlook


Program optimization, is the pursuit of the siege division must do things, so, of course, to optimize.



To save power, the following two policies are specified.



1. When the network changes, if there is no network, turn off the service and have the network, then turn on the service. The unlocking and the lock screen are turned on and off respectively.



2. There is a network, and screen opening is the necessary condition for triggering the service to open. Most can reduce the power consumption problem caused by the network change in the lock screen state of the application.



The above two strategies can be used overlay, there may be some problems, such as the conditions are met in some cases, but the service is not turned on (the network very frequent switching may be caused).



Set to the above conditions is because, the subsequent operation is a network to complete, and secondly, the lock screen state, the general user is not able to trigger the relevant process, unless the program automatically triggered (Instant messaging software to receive information such as, or automatic download, but this is too rogue) to need to run in the background lock screen.



HTTP server is used on GitHub on the open source nanohttpd, HTTP server in addition to high-speed download, but also can be used in, such as the transfer of data to the computer, application and Web page interaction and so on many aspects.


5. Final realization


Access http://m.app.sogou.com/ to see the final effect.



The general idea is the above description. I hope to inspire you and play a role.



Currently not online, estimated to wait until November 5.


6. Related tools and appendices


(1) Chrome developer Tools + Device mode (data capture)



(2) Three market download demo address: Baidu Mobile Assistant , Sogou Mobile assistant , pea pod



At that time (2014-10-27 page below)






(3) Common browser apk download path (#表示改行是注释, one directory per row, currently does not support traversing subdirectories)




#this is the binding apk file Path#this is a comment#some system default, Chrome, opera, Opera Mini, Sogou broswer, ES Fi Le Explorer,dolphin Browserdownload#meizu Browser, some system Defaultdownload/apkdownloads#uc BROWSERUCDOWNLOADS#QQ broswerqqbrowser/installation package qqbrowser/download QQBROWSER/DOWNLOAD#QQ broswer hdqqbrowser#baidu broswerbaidu/flyflow/downloads# Baidu Appbaidu/searchbox/downloads#maxthon broswermxbrowser/downloadsttdownload/ Installapkapplicationthunderdownload#liebao broswerkbrowser_fast/download/app# BroswerBrowser/download# Express broswer expressbrowser/download#2345 broswerdownload/2345 Browser download/install package #hao123hao123/down/ Apkdolphinbrowsercn/downloaducdlfilesqcdownloadlxdownload/downloadapc/apcbrowser/downloads#yuedong Broswer, Ignore,the apk file name is changed by the Broswer,the same with 4G Explorer (does not support header ' s content-disposition a Ttribute) #ydBrowser/download#4g-explorer/apks





Haha, perfect solution to all problems. can also be extended later.

















This article from Rxread's Blog, welcome reprint, reprint please specify.





Research and implementation of the high-speed download of Sogou market and the app page of Web page end


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.