is Ipad Or Iphone user agent - Java Network

Java examples for Network:User Agent

Description

is Ipad Or Iphone user agent

Demo Code


//package com.java2s;

import java.util.regex.Pattern;

public class Main {
    public static void main(String[] argv) throws Exception {
        String userAgent = "java2s.com";
        System.out.println(isIpadOrIphone(userAgent));
    }/*from  w  w  w. j  av a2 s.  com*/

    public static boolean isIpadOrIphone(String userAgent) {
        String browserName = userAgent.toLowerCase();
        String ipadRegx = ".*ipad.*";
        String iphoneRegx = ".*iphone.*";
        if (Pattern.matches(ipadRegx, browserName)
                || Pattern.matches(iphoneRegx, browserName)) {
            return true;
        } else {
            return false;
        }
    }
}

Related Tutorials