-4

I am using Webview to display some webpage , I wanted to know how to go Android Internet Setting when there is no Internet. I have provided a Button and when the user clicks on it , It should go to settings , Can it be done? if that is so Please tell me how to do this. Thanks .

This is the code I am using

       settings.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (haveNetworkConnection()) {
                reload.setVisibility(View.INVISIBLE);
                Sportee.this.webView.loadUrl("http://blah.blah.com");
            } else {
                reload.setVisibility(View.VISIBLE);
               //Here I have to write code to go for settings 
            Toast.makeText(getApplicationContext(), "Going to Settings", Toast.LENGTH_LONG).show();
            }
        }
    });

Function to check whether Internet is available or what

   private boolean haveNetworkConnection() {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }
    return haveConnectedWifi || haveConnectedMobile;
}
Sudhir Belagali
  • 370
  • 1
  • 7
  • 22

2 Answers2

3

You can open the settings page programmatically by using the following method:

startActivity(new Intent(
    Settings.ACTION_WIFI_SETTINGS));  //Or ACTION_WIRELESS_SETTINGS

Check out the full list of intent data you can use here

N Jay
  • 1,774
  • 1
  • 17
  • 36
  • sir it needs Bluetooth permission also – Sudhir Belagali Nov 02 '15 at 05:02
  • And that is why i provided the link so you can search for exactly which page you want to open in the settings and open it. Anyways here is the constant you are looking for ACTION_BLUETOOTH_SETTINGS – N Jay Nov 02 '15 at 05:04
0

Try this:

startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));

You can open different settings by checking the constants in Settings

Srujan Barai
  • 2,295
  • 4
  • 29
  • 52