English 中文(简体)
Configuring Android Web Applications
原标题:

iPhone web apps have four configuration features available (not including the HTML5 application cache) to configure how web pages behave when you save the web page to the home screen as a bookmark.

  1. You can specify the home page icon.
  2. You can specify a startup image that displays while the web page is loading.
  3. You can hide the browser UI.
  4. You can change the status bar color.

The four features work by adding tags to the <head> like this:

<link rel="apple-touch-icon" href="/custom_icon.png"/>
<link rel="apple-touch-startup-image" href="/startup.png">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />

Naturally, none of these "apple-" specific tags do anything in Android. But is there any way to do something equivalent? [At a minimum, I want users to be able to add my web page to their Android home screen (e.g. in Android 2.0) and have a pretty hi-res icon.]

最佳回答

This is a dated question, as such the answer has changed. Chrome on newer androids has it s own meta tags for this. Make sure you Add to the Homescreen, and launch from the homescreen. A normal bookmark is not sufficient. Chrome currently uses a few of the apple directives, but the three at the bottom are the android magic.

<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-startup-image" href="startup.png">
<link rel="apple-touch-icon" href="youricon.png"/>
<link rel="apple-touch-icon-precomposed" sizes="128x128" href="youricon.png">

<meta name="mobile-web-app-capable" content="yes">
<link rel="shortcut icon" sizes="196x196" href="youriconhighres.png">
<link rel="shortcut icon" sizes="128x128" href="youricon.png">
问题回答

When you create a shortcut on the home screen to a bookmark, Android will use a apple-touch-icon-precomposed if present (but not apple-touch-icon) as a high-res icon:

<link rel="apple-touch-icon-precomposed" href="/custom_icon.png"/>

As for the rest of the features, I don t think there s any way to do this at present without publishing an Android app that acts as a wrapper for your website.

This may be of interest to readers:

http://code.google.com/p/android/issues/detail?id=7657

In 2.1-update1, on the Droid, and I presume other 2.* OS phones, when adding a bookmark to the homescreen, the homescreen only displays a custom icon if the link rel="apple-touch-icon" or apple-touch-icon-precomposed have a FULL url path.

There are different meta elements that we can use to achieve the best results possible:

  1. First of all we need to set the viewport for our app as so:

    <meta name="viewport" content="width=device-width, initial-scale=1">
    

    There is a little hack here, for devices with taller screens (iPhone 5 for example):

    <meta name="viewport" content="initial-scale=1.0">
    

    Just put it under the other meta and it will do all the magic.

  2. Now that we have the basics, we will tell the mobile-browsers to "read" our website as if it was an app. There are two main meta elements:

    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    

    This will make our website to be opened in full-screen-mode and style the default status-bar.

  3. We are done with the "behaving" meta elements, now lets start with our icons. The amount of icons and code lines will depend totally on you. For the startup-image I prefered to create one icon for each resolution, so that my "loader" acts the same on all devices (mainly Apple devices). Here s how I did it:

    <!--iPhone 3GS, 2011 iPod Touch-->
    <link rel="apple-touch-startup-image" href="../images/mobile-icon-startup-320-460.png" media="screen and (max-device-width : 320px)">
    
    <!--iPhone 4, 4S and 2011 iPod Touch-->
    <link rel="apple-touch-startup-image" href="../images/mobile-icon-startup-640x920.png" media="(max-device-width : 480px) and (-webkit-min-device-pixel-ratio : 2)">
    
    <!--iPhone 5 and 2012 iPod Touch-->
    <link rel="apple-touch-startup-image" href="../images/mobile-icon-startup-640x1096.png" media="(max-device-width : 548px) and (-webkit-min-device-pixel-ratio : 2)">
    
    <!--iPad landscape-->
    <link rel="apple-touch-startup-image" sizes="1024x748" href="../images/mobile-icon-startup-1024x768.png" media="screen and (min-device-width : 481px) and (max-device-width : 1024px) and (orientation : landscape)">
    
    <!--iPad Portrait-->
    <link rel="apple-touch-startup-image" sizes="768x1004" href="../images/startup-768x1004.png" media="screen and (min-device-width : 481px) and (max-device-width : 1024px) and (orientation : portrait)">
    

    NOTE: The format must be PNG and all the sizes must be respected, otherwise it will not work.

  4. To finish, we will also need some icons for our app. This icon will be displayed on the devices menu. Here s how I did it:

    <!--iPhone 3GS, 2011 iPod Touch and older Android devices-->
    <link rel="apple-touch-icon" href="../images/mobile-icon-57.png">
    
    <!--1st generation iPad, iPad 2 and iPad mini-->
    <link rel="apple-touch-icon" sizes="72x72" href="../images/mobile-icon-72.png">
    
    <!--iPhone 4, 4S, 5 and 2012 iPod Touch-->
    <link rel="apple-touch-icon" sizes="114x114" href="../images/mobile-icon-114.png">
    
    <!--iPad 3rd and 4th generation-->
    <link rel="apple-touch-icon" sizes="144x144" href="../images/mobile-icon-144.png">
    

    NOTE: You can also use "precomposed" for your icon not to be shown with iOS reflective shine. Just add this word where you define rel as so:

    <link rel="apple-touch-icon-precomposed" href="../images/mobile-icon-57.png">
    

As said, this works better on Apple devices. But the app icon has been proved on Android devices and it works to.

I tried the above from my Samsung Galaxy S1

Didn t work for me... but what did work was first creating a bookmark and then adding that bookmark as a shortcut to my home. Doing this caused the correct icon to be used.





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签