Android web app icon being cut off the edges - android

I am making a web app, and when I "add to Home Screen" on my android device, the icon of my app is not being displayed properly. Below is the screenshot of it, and below that is what the icon really should look like:
This is the code I have inside the head tag of my website:
<link rel="shortcut icon" sizes="192x192" href="mydomain.com/img/site-icon/nice-highres.png">

Looked around the Add to Homescreen page for a while but it doesn't really mention any behavior on how the icon is scaled, but I found a tutorial about How to Add Icons and here, it mentions about creating the images available for all screen sizes:
If you don’t want to create all these images, you should at least create the larger resolution ones. That way they’ll look good on the hi-res devices. The older devices will load the closest size available to their required size and shrink them down (this works but isn’t ideal if you want complete control and the fastest download).
Based from this, you can presume that the icon MUST automatically be scaled down depending on the screen size. I'm not quite sure about this, but maybe what is causing your icon to not scale properly is because the rel attribute in your <link..> is incorrect? As per your code, it shows as rel="shortcut icon" while as per the Add to Homescreen doc, it should be rel="icon".
Also, a configuration is needed to support a homescreen launch, where you add some <meta> tags, like so (from the Add to Homescreen doc):
<!doctype html>
<html>
<head>
<title>Awesome app </title>
<meta name="viewport" content="width=device-width">
<meta name="mobile-web-app-capable" content="yes">
<link rel="icon" sizes="192x192" href="/icon.png">
</head>
<body></body>
</html>
Care to try it out and let me know if it works. Hope this helps somehow though. Good luck

When you size your logo with Android Studio they have a scale feature.
To size your logo:
1: Right-click app folder
2: Hover over "new" and click "create image asset"
Then resize with this tool:

as explained here (https://www.google.com/design/spec/style/icons.html#icons-system-icons), the icon dimension may be 48dp (and least for dense layout!).
After, the max size is relative to the user launcher...
I don't know what are the "perfect" dimensions in px (which are relative to the screen), but you may try to resize it by 48/48 (and also replace the "sizes" attribute)

On a specific device running Android 4.4.2 Jelly Bean, I found that the home screen icon would get cut off when the icon was larger than 92x92, even if 92x92 was also provided.
So just having this produces a great looking icon on the Jelly Bean device.
<link rel="icon" sizes="92x92" href="/favicon-92.png">
But the following will result in favicon-128.png being used on the Jelly Bean device, with the right and bottom sides being cropped. However, this does work on newer version of Android, as it should.
<link rel="icon" sizes="128x128" href="/favicon-128.png">
<link rel="icon" sizes="92x92" href="/favicon-92.png">
Since my web app is targeting a specific device running Jelly Bean, I decided to only provide the 92x92 icon. For websites in general I would recommend following Google's advice and provide low-res and high-res icons, which could cause issues on Jelly Bean devices.

Related

Conflicting Favicons

My Blogger site generates the following line:
<link href='http://www.mtscollective.com/favicon.ico' rel='icon' type='image/x-icon'/>
And I've also added the following line for Android to use when the site is saved to the home screen:
<link href='http://cdn.mtscollective.com/images/android/icon-196.png' rel='icon' sizes='196x196'/>
The problem is that sometimes Chrome and Firefox use these interchangeably, but I only want them to use the first line. Is it possible to control this?
Thanks
Firefox and Chrome tend to favor PNG pictures over favicon.ico. So you should also declare a 16x16 PNG picture, along with your existing 196x196 picture.
Also note that Firefox uses the last declared PNG picture (this is bug 751712). Make sure you declare the 16x16 picture last:
<link rel="shortcut icon" href="/path/to/icons/favicon.ico">
<link rel="icon" type="image/png" href="/path/to/icons/favicon-196x196.png" sizes="196x196">
<link rel="icon" type="image/png" href="/path/to/icons/favicon-16x16.png" sizes="16x16">
Finally, both Firefox and Chrome lack support for the sizes attribute. As a consequence, during the first visit, they will load both PNG pictures (these are bug 751712 (FireFox) and issue 324820 (Chrome)). This is not a serious issue, but good to know this.

Android width:100% fix (website takeover issue)

I'm making a website skin / takeover.
It looks good on all browsers except android, where the skin image css parameter (width: 100%) is seen as the screen width not as at least the website's width. So it doesn't wrap the website but stops at the device's screen width. Please see yourself, I cannot explain very good. What can I do?
The first image is the website loaded on galaxy S3 and the second image is the website a little scrolled to see the right side. Please edit my question if you have better words.
This is the temporary link until I will move it to the client: http://csengrosseto.digitalprimes.com
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
This is the version that also controls the zoom.

How to define the website screen shortcut icon?

I can't find how to make Android use a custom icon (e.g. the favicon or the app-touch image that iOS uses) for a website shortcut.
Can you give me a hint?
Android uses a home screen image AND a "Shortcut icon" (like favicon). If you only specify the home screen icon, the web page will not display an icon next to the URL in the web browser.
The "shortcut icon" must be listed separately, even though it can be the same file.
<link rel="shortcut icon" href="http://yourdomain.com/path/icon57.png" />
<link rel="apple-touch-icon" href="http://yourdomain.com/path/icon57.png" />
<link rel="apple-touch-icon" sizes="72x72" href="http://yourdomain.com/path/icon72.png" />
<link rel="apple-touch-icon" sizes="114x114" href="http://yourdomain.com/path/icon114.png" />
<link rel="apple-touch-icon" sizes="144x144" href="http://yourdomain.com/path/icon144.png" />
Relative URLs will work for many devices, but most sources say you need to use absolute URLs.
Listing the sizes separately allows the device to download only the smallest image that meets it's needs. For the "shortcut icon", you can't list different sizes, but you can use an ICO file which may contain multiple sizes encoded in the file. Many image programs like GIMP can save ICO files with multiple sizes.
Note that if you want the shortcut icon to display in IE, it must be a real ico file.
Apparently, Android versions 2.1 and earlier only recognize the "precomposed" image link, but if you include the precomposed icon, every device that is capable of "fancifying" icons will skip their process and just use the precomposed ones. The Androids I tested can do their own fancifying, so I don't use precomposed icon links. It will depend on your compatibility needs.
<link rel="apple-touch-icon-precomposed" href="http://yourdomain.com/custom_icon.png"/>
For more information about using home screen icons...
http://developer.apple.com/library/ios/#documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html
Android and iOS seem to use the same references for the icons on the home screen.
For the HTML link icons:
<!-- These two are what you want to use by default -->
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<link rel="apple-touch-icon-precomposed" href="apple-touch-icon-precomposed.png">
<!-- This one works for anything below iOS 4.2 -->
<link rel="apple-touch-icon-precomposed apple-touch-icon" href="apple-touch-icon-precomposed.png">
The difference between the two types are that the top two don't have a space. The bottom one includes both with a space in between. The space is not recognized by iOS 4.2+. Your best bet is to use all three. If you are limited on space, use only the top two.
For Sizes:
144 × 144 pixels for an iPad Retina display.
114 × 114 pixels for an iPhone Retina display.
57 × 57 pixels for almost anything else
One thing to watch out for is that iOS 4.2+ will simply ignore the size attribute, so you can just link them with out it. I'd suggest putting the size within the icon's file name just for organizational purposes.
Another thing to note is that you don't even need to include the links for the "apple-touch-icon"s. If there is no icons defined in the html, iOS will search through the root folder for files named the following in order. Android DOES need them defined, so put them in the code anyways.
apple-touch-icon-57x57-precomposed.png
apple-touch-icon-57x57.png
apple-touch-icon-precomposed.png
apple-touch-icon.png
This looks like a good explanation.
It would appear that if you place:
<link rel="apple-touch-icon" href="/path/to/some.png"/>
<link rel="apple-touch-icon-precomposed" href="/custom_icon.png"/>
In the bookmarked page's HTML, it will appear on the desktop automagically.
This Android and iPhone icon page suggests absolute URLs for Android.
So just amend KenY-N's tags to
<link rel="apple-touch-icon" href="http://yourdomain.com/path/to/some.png"/>
<link rel="apple-touch-icon-precomposed" href="http://yourdomain.com/custom_icon.png"/>
I can confirm it works using relative (and absolute was working for me too)... but clearing caching solved what issues i was having... sample lines i used:
<!-- fj Icon for Android Chrome shortcut etc-->
<link rel="apple-touch-icon" href="/static/main/img/m3magnet-full.png">
<link rel="apple-touch-icon-precomposed" href="/static/main/img/m3magnet-full.png">
this is what worked for me. Chrome on Android:
<link rel="icon" type="image/png" href="favicon.png" />
<link rel="shortcut icon" href="favicon.ico" />
<link
rel="apple-touch-icon"
sizes="64x64"
href="http://glatocha.com/bmr/favicon.png"
/>
<link
rel="apple-touch-icon-precomposed"
href="http://glatocha.com/bmr/favicon.png"
/>

Full webpage and disabled zoom viewport meta tag for all mobile browsers

I want my webpage to be full screen and disable zooming on all mobile devices.
With the meta tag:
<meta name="viewport" content="width=1165, user-scalable=no">
I am able to do this for iPhone/iPad, but on Android devices the website is zoomed in to about 125%.
If I use the tag
<meta name="viewport" content="width=max-device-width, user-scalable=no">
I get the opposite result. So then it works on Android but it doesn't work on iPad/iPhone.
Unfortunately each browser has it's own implementation of the viewport meta tag. Different combinations will work on different browsers.
Android 2.2: viewport meta tag does not seem to be supported at all.
Android 2.3.x/3.x: By setting user-scalable=no you disable the scaling of the viewport meta tag yourself as well. This is probably why your width option is having no effect. To allow the browser to scale your content, you need to set user-scalable=yes, then to disable zoom you can set the min and max scale to the same value so it cannot shrink or grow. Toy with the initial scale until your site fits snugly.
<meta name="viewport" content="initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,width=device-width,height=device-height,target-densitydpi=device-dpi,user-scalable=yes" />
Android 4.x: Same rule apply as 2.3.x except the min and max scales are not honored anymore and if you use user-scalable=yes the user can always zoom, setting it to 'no' means your own scale is ignored, this is the issue I'm facing now that drew me to this question... You cannot seem to disable zoom and scale at the same time in 4.x.
iOS/Safari (4.x/5.x tested): Scales work as expected, you can disable scaling with user-scalable=0 (keywords yes/no don't work in 4.x). iOS/Safari also has no concept of target-densitydpi so you should leave that out to avoid errors. You don't need min and max since you can switch off zooming in the expected manner. Only use width or you'll run into the iOS orientation bug
<meta name="viewport" content="initial-scale=1.0,width=device-width,user-scalable=0" />
Chrome: Scales work as expected like they do in iOS, min and max are honored and you can switch off zooming by using user-scalable=no.
<meta name="viewport" content="initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,width=device-width,user-scalable=no" />
Conclusion: You can use some fairly simple JS to set the content accordingly after some basic browser/device detection. I know this type of detection is frowned upon but in this case it's almost unavoidable because each vendor has gone and done their own thing! Hope this helps people fighting the viewport, and if anyone has a solution for disabling zooming in Android 4.x WITHOUT the use of the viewport, please let me know.
[EDIT]
Android 4.x Chrome browser (which I think is pre-installed in most countries): You can make sure the user cannot zoom and the page is fullscreen. The downside: you have to make sure the content has a fixed width. I haven't tested this on lower Android versions. To do this see the example:
<meta name="viewport" content="width=620, user-scalable=no" />
[EDIT 2]
iOS/Safari 7.1: Since v7.1, Apple have introduced a new flag for the viewport meta tag called minimal-ui. To assist with full screen apps, this hides the address bar and bottom toolbar for a full-screen experience (not quite Full Screen API but close and doesn't require user acceptance). It does comes with it's fair share of bugs as well and doesn't work in iPads.
<meta name="viewport" content="initial-scale=1.0,width=device-width,user-scalable=0, minimal-ui" />
[EDIT 3]
iOS/Safari 8 Beta 4: The viewport meta tag minimal-ui mentioned in EDIT 2 has now been removed by Apple in this release. Source - WebKit Notes
HTML
<head>
<meta name='viewport' content='width=device-width,initial-scale=1,maximum-scale=1'>
</head>
jQuery
Option 1:
$('meta[name=viewport]').attr('content','width='+$(window).width()+',user-scalable=no');
Option 2:
var deviceSpecific = {
iPad: 'width=1165,user-scalable=no'
};
if(navigator.userAgent.match(/iPad/i){
$('meta[name=viewport]').attr('content',deviceSpecific.iPad);
}
Option two being a bit more of a last resort if you're finding inconsistency.
Simply use:
<meta name="HandheldFriendly" content="True" />
Works well on my Samsung Note II and HTC Desire.
For Apple devices is easy:
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0" />
The first tag run the web app in full screen mode when you open it via a shortcut icon placed on the iPhone/iPod/iPad home screen.
The second tags works only in conjunction with the first one. Possible values are: default, black and black-translucent.
The third tag blocks the site width to its standard size (1.0) and does not allow zooming.
NOTE: as the "apple-mobile" meta tags are ignored on non-Apple devices and the 3rd tag is official in HTML5, you can use all of them together.
For Android you have not a global solution since not everybody uses the default android webbrowser. See Fullscreen Web App for Android
Here some other useful links:
Tips for iOS:
http://matt.might.net/articles/how-to-native-iphone-ipad-apps-in-javascript/
All the official and unofficial known meta: https://gist.github.com/kevinSuttle/1997924
Android fixed it from version 4.4.2
<meta name="viewport" content="initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,width=device-width,height=device-height,target-densitydpi=device-dpi,user-scalable=yes" />
I have a Samsung Galaxy Note 4 and use chrome as my browser. I found it was ignoring the viewport meta tags, got it to work with HandheldFriendly. I ended up with a meta tag combo. Works for me on Android and iOS.
<meta name="HandheldFriendly" content="True">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="width=YOUR_SITE_WIDTH">
I was having all kinds of problems with this and even started to build a browser detection system to deliver different viewport tags to different browsers. Then I decided to try simplifying what I was doing and everything worked. Set the viewport to the width you want your site to be and walk away everything is working now.
<meta name="viewport" content="width=1165 />
For what it's worth, here's what I used to get a 1024px width content page to go exactly full screen on my Nexus 7 (Android 4.2.2)/Chrome, landscape only without resorting to javascript*:
width=device-width, initial-scale=.94, minimum-scale=0.8, maximum-scale=1.2, user-scalable=no
(I think the user-scalable=no actually negates the min- & max-scale though). I got the .94 value by trial and error, not by any sort of calculation invoking device pixel density or anything like that.
*i.e. to force content width to match window -- I did use js to conditionally write the viewport meta content.
<meta name="viewport" content="width=device-width; height=device-height; maximum-scale=1.4; initial- scale=1.0; user-scalable=yes"/>
We used the following Javascript in the header to set the meta tags:
<script>
if (navigator.userAgent.match(/(iPad|iPhone|iPod)/g) {
document.write("<meta name='viewport' content='width=1165, user-scalable=no'>"); // or whichever meta tags make sense for your site
} else {
document.write("<meta name='viewport' content='width=max-device-width, user- scalable=no'>"); // again, which ever meta tags you need
}
</script>
You could add additional conditions and set them for your specific needs.
The below suggestion from Dan B has worked great for me, i have been having all sorts of issues trying to get my site to load right on android, and this has sorted it. For now anyways!
<meta name="viewport" content="width=YOUR_SITE_WIDTH"/>
Thanks!
I am using this code to prevent zoom in iPhone and problem was solved but another problem arises; when I click on input field whole window jumps up then sets its position to normal, when i pressed go button same behavior occurs and windows jumps. i need to get rid of jump so that only window resizes it to normal location.
function zoomDisable(){
$('head meta[name=viewport]').remove();
$('head').prepend('<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0" />');
}

How to change the default Android bookmark icon?

I keep getting the default Android ribbon bookmark icon, instead of my 114x114 icon for web app. Ideas?
I have tried ...
<link rel="apple-touch-icon" href="/icon.png"/>
<link rel="apple-touch-icon" href="/apple-touch-icon.png"/>
<link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-precomposed.png"/>
<link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-114x114-precomposed.png"/>
I have also tried an approach similar to:
if (useragent == blackberry){
use precomposed/use 114x114-precomposed
}
In all variations, I continue to get the default ribbon icon, with the favicon centered in the middle of the ribbon. Isn't it possible to create a home page icon in Android that looks like a native app?
I have iOS and BlackBerry devices handled, but I am having no luck with Androids. It also doesn't seem to matter what browser I use.
Do I need to have full path including domain location? Other ideas?
take à look at this ;)
Configuring Android Web Applications
or this
http://www.mollerus.net/tom/blog/2010/06/web_app_homescreen_icons_in_android.html
this
it should work, it may not work because your path is not the right one, make sure your image is at the root of your web server because you included '/' before your path

Categories

Resources