Java
[Java] μ¬μ©μ Web/App/Mobile μ μ ꡬλΆνκΈ°
Jo__y
2022. 10. 14. 13:46
User Agent
μ¬μ©μκ° μ΄λ€ λλ°μ΄μ€λ‘ μ μνλμ§μ λν μ λ³΄κ° νμν λ Request Header μ User Agent λ‘ νμΈ ν μ μλ€.
User Agent κ° κ°μ§κ³ μλ μ 보 μμ
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36
public void getUserDevice(HttpServletRequest request) {
String userAgent = request.getHeader("User-Agent");
// λͺ¨λ°μΌ κΈ°μ’
체ν¬
boolean isMobile = userAgent.matches(".*(iPhone|iPod|iPad|BlackBerry|Android|Windows CE|LG|MOT|SAMSUNG|SonyEricsson).*");
// APP_ios, APP_Andriod λ± κ΅¬λΆνκ³ μ νλ μ±μ νΉμ λ³μ
if(userAgent.indexOf("APP_ios") > -1 || userAgent.indexOf("APP_Andriod") >-1){
System.out.println("App μΌλ‘ μ μ");
}else if(isMobile){
System.out.println("Mobile μΌλ‘ μ μ");
}else {
System.out.println("Web μΌλ‘ μ μ");
}
}λ°μν