Possible Duplicate:
Android detect if device has internet connection
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.
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.
How can i do it? Please help me.
My Main Activity:
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); }
});
}
}
I appreciate for your help.