Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8154715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:26:59+00:00 2026-06-06T16:26:59+00:00

My application uses HttpURLConnection to connect to my REST services. I log errors and

  • 0

My application uses HttpURLConnection to connect to my REST services. I log errors and noticed that what happens occasionally is that user get’s WiFi connection but it has proxy.

For example, those airport wifi’s that redirect you to pay pages and then let you use internet. My code does not follow redirects.

What I really want is to ignore presence of WiFi and force communication over 3G/4G/E whatever. How can I do that on Android?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:27:00+00:00Added an answer on June 6, 2026 at 4:27 pm

    Switch to mobile network:

    As soon as you detect a proxy, pop up a dialog telling the user that your app cannot use that network and hence you are switching to the mobile network. You can switch to a mobile network using ConnectivityManagerclass.

    ConnectivityManager cm; 
    cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    cm.setNetworkPreference(ConnectivityManager.TYPE_MOBILE);
    

    and switch back to the default when you are done:

    cm.setNetworkPreference(ConnectivityManager.DEFAULT_NETWORK_PREFERENCE);
    

    Detect a proxy:

    Detect proxy using the following snippet

    HttpURLConnection conn;
    ...
    if (conn.getResponseCode() == HTTP_PROXY_AUTH){
        // You got a '407: Proxy authentication required' response.
        // Set the networkPreference() here and retry when 
        // network connection changes to TYPE_MOBILE.
    }
    

    You can check this post to know how to use a HttpURLConnection through a proxy : How do I make HttpURLConnection use a proxy?

    Detect a ‘network change’:

    To know how to detect ‘network change’ see this post :
    Android, How to handle change in network (from GPRS to Wi-fi and vice-versa) while polling for data

    Update:

    If you cannot show a dialog, at least send a status bar Notification so that user knows about the network switch sometime later.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application uses some third-party libraries. I need to log some exceptions that occur
My application uses MS access database to save some sensitive information. Though that information
Our application uses SQL Server Reporting Services and allows users to add custom filters
My application uses the following codes to connect to web site and download a
We have an application that uses a JAX-RPC client library and is running on
Our application uses a XML configuation file. I thought that it would be nice
My application uses tcp to connect to my server and I am packet sniffing
Our application uses several back-end services and we maintain wrappers which contain the methods
My application uses the OAuth2 gem (0.1.1) to connect to Facebook, and the ActiveMerchant
My application uses quite a lot of pictures that are downloaded from the internet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.