Android Network access proxy

Source: Internet
Author: User

During Android network development, you need to determine whether the current network connection mode is wifi or wap. If it is wap, you need to use proxy for access.

Why is proxy access required?


WAP is only a GPRS application mode, and it has nothing to do with the GRPS access mode. WAP applications adopt the "terminal + WAP Gateway + WAP Server" mode, which is different from the general "terminal + server" mode of Internet. The main purpose is to achieve WAP-WEB protocol conversion through WAP gateway to save network traffic and compatible with existing WEB applications.


private boolean isNeedProxy(final Context context)    {        boolean ret = false;        final ConnectivityManager connectManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);        final NetworkInfo activeNetInfo = connectManager.getActiveNetworkInfo();        if (activeNetInfo != null)        {            final String type = activeNetInfo.getTypeName();            // WIFI not available            if (type.equalsIgnoreCase("WIFI"))            {                ret = false;            }            //Mobile             else if (type.equalsIgnoreCase("MOBILE"))            {                final String mobileProxyIp = android.net.Proxy.getHost(context);                final int mobileProxyPort = android.net.Proxy.getPort(context);                if (mobileProxyIp == null || "".equals(mobileProxyIp)                        || mobileProxyPort == 0)                {                    ret = false;                }                else                {                    hostUrl = mobileProxyIp;                    hostPort = mobileProxyPort;                                      ret = true;                }            }        }        return ret;    }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.