根據(jù)USER-AGENT判斷手機(jī)類型并跳轉(zhuǎn)到相應(yīng)的app下載頁(yè)面
實(shí)現(xiàn)的原理,是檢測(cè)瀏覽器的 USER-AGENT 這個(gè)header,然后根據(jù)正則表達(dá)式來(lái)確定客戶端類型。
如果都不匹配,F(xiàn)allback回退策略是顯示對(duì)應(yīng)的頁(yè)面,讓用戶自己選擇。
適合采用二維碼掃描方式下載APP:
JSP版本的代碼如下所示:其他服務(wù)端版本請(qǐng)百度搜索。
<%@page import="java.util.regex.Matcher"%> <%@page import="java.util.regex.Pattern"%> <%@ page language="java" pageEncoding="UTF-8"%> <%! // \b 是單詞邊界(連著的兩個(gè)(字母字符 與 非字母字符) 之間的邏輯上的間隔),字符串在編譯時(shí)會(huì)被轉(zhuǎn)碼一次,所以是 "\\b" // \B 是單詞內(nèi)部邏輯間隔(連著的兩個(gè)字母字符之間的邏輯上的間隔) String androidReg = "\\bandroid|Nexus\\b"; String iosReg = "ip(hone|od|ad)"; Pattern androidPat = Pattern.compile(androidReg, Pattern.CASE_INSENSITIVE); Pattern iosPat = Pattern.compile(iosReg, Pattern.CASE_INSENSITIVE); public boolean likeAndroid(String userAgent){ if(null == userAgent){ userAgent = ""; } // 匹配 Matcher matcherAndroid = androidPat.matcher(userAgent); if(matcherAndroid.find()){ return true; } else { return false; } } public boolean likeIOS(String userAgent){ if(null == userAgent){ userAgent = ""; } // 匹配 Matcher matcherIOS = iosPat.matcher(userAgent); if(matcherIOS.find()){ return true; } else { return false; } } %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; // String userAgent = request.getHeader( "USER-AGENT" ).toLowerCase(); System.out.println("userAgent: "+userAgent); if(null == userAgent){ userAgent = ""; } if(likeAndroid(userAgent)){ System.out.println("likeAndroid: "+true); response.sendRedirect("http://m.iyhjy.com/download.jsp?platform=android"); return; //request.getRequestDispatcher("/download.html").forward(request,response); } else if(likeIOS(userAgent)){ System.out.println("likeIOS: "+true); response.sendRedirect("http://itunes.apple.com/us/app/id714751061"); return; //request.getRequestDispatcher("/index.html").forward(request,response); } %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"> <title>下載客戶端 - 永恒記憶</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="p_down"> <div> <a href="index.html"> <img src="images/p_logo.png" class="p_logo" /> </a> </div> <a href="itms-services://?action=download-manifest&url=http://m.iyhjy.com/upload/client/yhjyios.plist" class="apple download"><img src="images/p_down_apple.png" /></a> <a class="download"><img src="images/p_down_and.png" /></a> </div> </body> </html>
相關(guān)文章
Android6.0指紋識(shí)別開發(fā)實(shí)例詳解
這篇文章主要介紹了Android6.0指紋識(shí)別開發(fā)實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-04-04Android調(diào)用系統(tǒng)裁剪的實(shí)現(xiàn)方法
下面小編就為大家分享一篇Android調(diào)用系統(tǒng)裁剪的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-02-02Android View實(shí)現(xiàn)圓形進(jìn)度條
這篇文章主要為大家詳細(xì)介紹了Android View實(shí)現(xiàn)圓形進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08Android使用ListView實(shí)現(xiàn)滾輪的動(dòng)畫效果實(shí)例
這篇文章主要介紹了Android使用ListView實(shí)現(xiàn)滾輪的動(dòng)畫效果實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06RecyclerView實(shí)現(xiàn)常見(jiàn)的列表菜單
這篇文章主要為大家詳細(xì)介紹了用RecyclerView實(shí)現(xiàn)移動(dòng)應(yīng)用中常見(jiàn)的列表菜單,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12Android 如何獲取設(shè)備唯一標(biāo)識(shí)
這篇文章主要介紹了Android 如何獲取設(shè)備唯一標(biāo)識(shí),幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下2021-03-03總結(jié)Android中多線程更新應(yīng)用的頁(yè)面信息的方式
這篇文章主要介紹了總結(jié)Android中多線程更新應(yīng)用的頁(yè)面信息的方式,文中共總結(jié)了runOnUiThread、Handler、AsyncTask異步以及View直接在UI線程中更新的方法,需要的朋友可以參考下2016-02-02Android AlarmManager實(shí)現(xiàn)定時(shí)循環(huán)后臺(tái)任務(wù)
這篇文章主要為大家詳細(xì)介紹了Android AlarmManager實(shí)現(xiàn)定時(shí)循環(huán)后臺(tái)任務(wù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-06-06Android Intent傳遞數(shù)據(jù)底層分析詳細(xì)介紹
這篇文章主要介紹了Android Intent傳遞數(shù)據(jù)底層分析詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下2017-02-02Android直播系統(tǒng)平臺(tái)搭建之圖片實(shí)現(xiàn)陰影效果的方法小結(jié)
這篇文章主要介紹了Android直播系統(tǒng)平臺(tái)搭建, 圖片實(shí)現(xiàn)陰影效果的若干種方法,本文給大家?guī)?lái)三種方法,每種方法通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2021-08-08