How to check Use network-provided values checkbox programatically in android

StackOverflow https://stackoverflow.com/questions/20993459

  •  25-09-2022
  •  | 
  •  

Вопрос

it is possible to check use network provided values chekbox pro-grammatically?I want to check that checkbox using code.How can I do it?

I want to check marked checkbox using programme

Это было полезно?

Решение 2

Try this:

YourActivity.this.startActivity(new Intent(Settings.ACTION_DATE_SETTINGS));

It is not possible to enable it directly from your code. This code will help you to automatically go to that screen.You can then check or uncheck it and then return back to the your screen.

Другие советы

android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.Global.AUTO_TIME)

0 - not checked 1 - checked

Answer Credits Matthias Robbers

public class ConnectionDetector {

        private Context _context;

        public ConnectionDetector(Context context){
            this._context = context;
        }

        /**
         * Checking for all possible internet providers
         * **/
        public boolean isConnectingToInternet(){
            ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
              if (connectivity != null)
              {
                  NetworkInfo[] info = connectivity.getAllNetworkInfo();
                  if (info != null)
                      for (int i = 0; i < info.length; i++)
                          if (info[i].getState() == NetworkInfo.State.CONNECTED)
                          {
                              return true;
                          }

              }
              return false;
        }
    }

This question is similar to: how to turn internet connection (GPRS/EDGE/3G) on/off

Have a look at the project mentioned in the answer:http://code.google.com/p/apndroid/

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top