How to detect Internet Connection
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/6493517/android-detect-if-device-has-internet-connection">Android detect if device has internet connection</a>  </p>
</blockquote>



<p>I have one program that I allow only android user that has internet connected can access, other user that don't have internet connection alert them to connect to the internet, if not connect problem will exit.</p>

<p>My main activity code is bellow. I want if mobile user has internet connected will show Main Layout, but if not connected alert user to connect Internet first.</p>

<p>How can i do it? Please help me.</p>

<h1>My Main Activity:</h1>

<pre><code>public class MainSong extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


  //My Profile
    Button myProfile = (Button) findViewById(R.id.myprofile);


    myProfile.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent();
            i.setClassName("aaa.bbb.ccc", "aaa.bbb.ccc.myprofile");
            startActivity(i); }
    });

  //My Songs
    Button mySong = (Button) findViewById(R.id.mysongs);
    mySong.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent();
            i.setClassName("aaa.bbb.ccc", "aaa.bbb.ccc.mysong");
            startActivity(i); }
    });

    //bar album
    Button album = (Button) findViewById(R.id.myalbum);
    album.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent();
            i.setClassName("aaa.bbb.ccc", "aaa.bbb.ccc.myalbum");
            startActivity(i); }
    });

    //bar video
    Button video = (Button) findViewById(R.id.myvideo);
    video.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent();
            i.setClassName("aaa.bbb.ccc", "aaa.bbb.ccc.myvideo");
            startActivity(i); }
    });
}
}
</code></pre>

<p>I appreciate for your help.</p>
