Possible Duplicate:
Android detect if device has internet connection
我有一个程序,我只允许有互联网连接的机器人用户进入, 其他没有互联网连接的用户提醒他们连接互联网, 如果不连接问题, 就会退出。
我的主要活动代码是bellow。 如果移动用户有互联网连接, 我要显示主布局, 但如果没有连接到警示用户, 请先连接互联网 。
我该怎么做?
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); }
});
}
}
谢谢你的帮助