Returns a random mobile browser user agent String from #MOBILE_USER_AGENTS array. - Java Network

Java examples for Network:User Agent

Description

Returns a random mobile browser user agent String from #MOBILE_USER_AGENTS array.

Demo Code


//package com.java2s;
import java.util.Random;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(getRandomMobileUserAgent());
    }/*from   w  w w.  j  a va  2 s.  c  o  m*/

    public static final String MOBILE_USER_AGENTS[] = {
            "Mozilla/5.0 (Linux; Android 4.1.2; GT-I9300 Build/JZO54K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.63 Mobile Safari/537.36 OPR/15.0.1162.61541",
            "Mozilla/5.0 (Linux; U; Android 4.1.2; el-gr; GT-P5100 Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30",
            "Mozilla/5.0 (Linux; U; Android 4.1.1; el-gr; HTC_One_S Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
            "Mozilla/5.0 (Linux; U; Android 4.1.2; el-gr; GT-P3110 Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30",
            "Mozilla/5.0 (Linux; U; Android 4.0.4; el-gr; SonyST21i2 Build/11.0.A.6.5) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
            "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG; GT-I8350)" };

    /**
     * Returns a random mobile browser user agent String from
     * {@link #MOBILE_USER_AGENTS} array.
     *
     */
    public static String getRandomMobileUserAgent() {

        return MOBILE_USER_AGENTS[new Random()
                .nextInt(MOBILE_USER_AGENTS.length)];
    }
}

Related Tutorials