Android hybrid development, HTML5 automatically updates crawled pits

Source: Internet
Author: User

Now there are more and more companies using hybrid development, although some new technologies, such as Facebook's react native, Ali's Weex, still block the determination of some companies to adopt H5, which, of course, is a multifaceted choice.

Three years ago, the use of HTML5 hybrid development, was doing a precious metal software, staff, the universe trading, as well as the information of various stock markets, at that time or on the eve of the outbreak of a bull market, hey ...

Recently the company let with H5 mixed development, some pages and functions have H5 share, initially placed in the local assets folder, and later because the front-end colleagues frequently modified and updated, coupled with data security considerations, decided to put the package on the server, using interface return field to determine whether the need to download updates, Next talk about the development of a few pits, to make a note for themselves, but also to share to the needs of friends.

First Pit: Android system

For the mixed development of H5, Android system is a big pit, three years ago when the access to H5 point, then a lot of mobile phone cards with PPT-like, 4.0 after Google to do some optimization, the efficiency is really good, but the back of a series of giant pits, For example, 4.3 before a kernel, 4.3 a separate kernel, 4.3 is a kernel, the original webview can not achieve overall compatibility, finally adopted a scheme, using the big Penguin X5 kernel, the advantages are as follows:

    1. Inside the class name and method name, and the original name is almost the same, the use of more convenient
    2. QQ and are all using x5 kernel, kernel sharing, do not need to download separately
    3. Relatively good compatibility

Two pits: Downloadmanager.

The original plan is to use the system under the class Downloadmanager, since it is the system provided, many code friends certainly feel very OK, but the demolition force blind, Samsung's mobile phone system has Downloadmanager API deleted, this is disgusting, you still continue to play explosion it ...

Three pits: WebView loading does not show

Before the assets, the page display is 6, instead of downloading to the local read, actually do not show, print the next path, no problem, then you can determine the problem in the loading process, check the information found, can be used LoadData, this method needs to first read the HTML file, By passing the string into the LoadData, you can show the page, but not the CSS, JS and other files. You can also use Loadurl, but be aware that this is because local data is used, so incoming URLs need to be processed, for example:

    1. If the HTML file is stored in assets: prefix: file:///android_asset/
    2. If the HTML file is stored in sdcard: prefix: content://com.android.htmlfileprovider/sdcard/

Ps:content prefixes can cause exceptions, and direct use of file:///sdcard/or File:/sdcard may also

Four pits: escape of special characters

There is a page, iOS colleagues over there has always been shown normal, Android this side can not come out, the same page different data page display page, then feel very strange, should not be H5 point problem, or iOS will not show, print the URL to see, wipe, the URL has a "%", After escaping, it will be OK. Of course, there are some special characters that need to be escaped as needed, and "%" is just an example.

Code has not been stripped from the company project, currently not uploaded, if there are errors or additions, a lot of advice.

Android hybrid development, HTML5 automatically updates crawled pits

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.