rivate class JsObject {
? ? ? ?
? ? ? @java scriptInterface
? ? ? public void onReceivedTouchIcons(String url, String json) {
? ? ? ? ? Log.i(LOGTAG, "onReceivedTouchIcons url=" + url + ";json=" + json);
? ? ? }
? }
? ?
? private String getTouchIconJsCode() {
? ? ? StringBuilder total = new StringBuilder();
? ? ? InputStream inputStream = null;
? ? ? BufferedReader bufferReader = null;
? ? ? try {
? ? ? ? ? inputStream = getAssets().open("touchicon.js");
? ? ? ? ? bufferReader = new BufferedReader(new InputStreamReader(inputStream));
? ? ? ? ? String line;
? ? ? ? ? while ((line = bufferReader.readLine()) != null) {
? ? ? ? ? ? ? total.append(line);
? ? ? ? ? }
? ? ? } catch (FileNotFoundException e) {
? ? ? ? ? e.printStackTrace();
? ? ? } catch (IOException e) {
? ? ? ? ? e.printStackTrace();
? ? ? } finally {
? ? ? ? ? if (null != inputStream) {
? ? ? ? ? ? ? try {
? ? ? ? ? ? ? ? ? inputStream.close();
? ? ? ? ? ? ? } catch (IOException e) {
? ? ? ? ? ? ? ? ? e.printStackTrace();
? ? ? ? ? ? ? }
? ? ? ? ? }
? ? ? }
? ? ? return total.toString();
? }
}
返回的JSON数据
我们可以对得到的JSON数据按照需要处理。
Google会改进么
答案是会,而且已经改进,但Google修改的不是onReceivedTouchIconUrl这个方法,而是Google正在推行自己的一套规则。
在Chrome上,Google增加了这样一个元素,这是Google提供的为网页程序定义元数据的方法。
在元数据json中,你可以自定义title,起始页,程序是横屏还是竖屏展示。一个简单地json实例如下,这里我们???以看到其中icons中存在多个类似touch icon的图标,src代表图标路径,sizes代表大小,type就是mimetype,density指的是Android中的屏幕密度(这样更加Android化了)。
{
? "name": "Web Application Manifest Sample",
? "icons": [
? ? {
? ? ? "src": "launcher-icon-0-75x.png",
? ? ? "sizes": "36x36",
? ? ? "type": "image/png",
? ? ? "density": "0.75"
? ? },
? ? {
? ? ? "src": "launcher-icon-1x.png",
? ? ? "sizes": "48x48",
? ? ? "type": "image/png",
? ? ? "density": "1.0"
? ? },
? ? {
? ? ? "src": "launcher-icon-1-5x.png",
? ? ? "sizes": "72x72",
? ? ? "type": "image/png",
? ? ? "density": "1.5"
? ? },
? ? {
? ? ? "src": "launcher-icon-2x.png",
? ? ? "sizes": "96x96",
? ? ? "type": "image/png",
? ? ? "density": "2.0"
? ? },
? ? {
? ? ? "src": "launcher-icon-3x.png",
? ? ? "sizes": "144x144",
? ? ? "type": "image/png",
? ? ? "density": "3.0"
? ? },
? ? {
? ? ? "src": "launcher-icon-4x.png",
? ? ? "sizes": "192x192",
? ? ? "type": "image/png",
? ? ? "density": "4.0"
? ? }
? ],
? "start_url": "index.html",
? "display": "standalone",
? "orientation": "landscape"
}
但是由于目前,这种标准实施率相对比较低,所以我们还是需要使用苹果的touch icon。
源码下载:
------------------------------------------分割线------------------------------------------
具体下载目录在 /2015年资料/1月/28日/Android中处理Touch Icon的方案/
------------------------------------------分割线------------------------------------------