title: how to check internet connection on splash screen
body: <p>I'm getting the following errors:</p>
  
  <ol>
  <li><p><code>ACTION_WIRELESS_SETTINGS</code> cannot be resolved or is not a field <code>(build = new Builder(Context); )</code></p></li>
  <li><p>Context cannot be resolved to a variable <code>(build = new Builder(Context); )</code></p></li>
  <li><p>Type mismatch: <code>cannot convert from AnimatorSet.Builder to AlertDialog.Builder(  startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));)</code></p></li>
  </ol>
  
  <p><strong>SplashScreen.java</strong></p>
  
  <pre><code>public class SplashScreen extends Activity {
  static ConnectivityManager cm;
  AlertDialog dailog;
  AlertDialog.Builder build;
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
  build = new Builder(Context); 
  
   if (cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
       .isConnectedOrConnecting()
       || cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
               .isConnectedOrConnecting()// if connection is
  // there screen goes
  // to next screen
  // else shows
  // message toast
  ) {
   Log.e("cm value", "" + cm.getAllNetworkInfo().toString());
   Toast.makeText(SplashScreen.this, "Internet is active", 2000)
           .show();
   Thread mythread = new Thread() {
       public void run() {
           try {
  
               sleep(5000);
  
           } catch (Exception e) {
           } finally {
               Intent intent = new Intent(SplashScreen.this,
                       MainActivity.class);
               startActivity(intent);
               finish();
           }
       }
   };
   mythread.start();
  } else {
  
   build.setMessage("This application requires Internet connection.Would you connect to            internet ?");
   build.setPositiveButton("Yes", new OnClickListener() {
  
       @Override
       public void onClick(DialogInterface dialog, int which) {
           // TODO Auto-generated method stub
           finish();
           startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
  
       }
   });
   build.setNegativeButton("No", new OnClickListener() {
  
       @Override
       public void onClick(DialogInterface dialog, int which) {
           // TODO Auto-generated method stub
           build.setMessage("Are sure you want to exit?");
           build.setPositiveButton("Yes", new OnClickListener() {
  
               @Override
               public void onClick(DialogInterface dialog, int which) {
                   // TODO Auto-generated method stub
                   finish();
               }
           });
           build.setNegativeButton("NO", new OnClickListener() {
  
               @Override
               public void onClick(DialogInterface dialog, int which) {
                   // TODO Auto-generated method stub
                   finish();
                   Intent intent = new Intent(SplashScreen.this,
                           SplashScreen.class);
                   startActivity(intent);
  
                   dialog.dismiss();
  
               }
           });
           dailog = build.create();
           dailog.show();
       }
   });
   dailog = build.create();
   dailog.show();
  
  }
  
   }
  
  @Override
    public boolean onCreateOptionsMenu(Menu menu) {
   // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
   return true;
   }
   }
  </code></pre>