网络判断状态
来源:互联网 发布:淘宝运营怎么学 编辑:程序博客网 时间:2024/05/13 11:04
public class MainActivity extends Activity
{
private CheckBox mBox;
private Editor edit;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences sp = getSharedPreferences("isWifi", 0);
edit = sp.edit();
mBox = (CheckBox) findViewById(R.id.checkBox1);
mBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
edit.putBoolean("wifi", isChecked);
edit.commit();
}
});
boolean isAuto = sp.getBoolean("wifi", true);
if (isAuto)
{
if (ConnectionUtils.isWIFI(this))
{
Toast.makeText(this, "WIFI连接,自动下载中。。。", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(this, "非WIFI连接,不下载", Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(this, "未选中,不自动下载", Toast.LENGTH_SHORT).show();
}
}
public void contection(View v){
if (ConnectionUtils.isConnected(this))
{
if (ConnectionUtils.isWIFI(this))
{
Toast.makeText(this, "WIFI连接", Toast.LENGTH_SHORT).show();;
}
else if (ConnectionUtils.isMobile(this))
{
Toast.makeText(this, "移动网络连接", Toast.LENGTH_SHORT).show();;
}
}
else{
Toast.makeText(this, "网络未连接", Toast.LENGTH_SHORT).show();;
}
}
}
{
private CheckBox mBox;
private Editor edit;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences sp = getSharedPreferences("isWifi", 0);
edit = sp.edit();
mBox = (CheckBox) findViewById(R.id.checkBox1);
mBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
edit.putBoolean("wifi", isChecked);
edit.commit();
}
});
boolean isAuto = sp.getBoolean("wifi", true);
if (isAuto)
{
if (ConnectionUtils.isWIFI(this))
{
Toast.makeText(this, "WIFI连接,自动下载中。。。", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(this, "非WIFI连接,不下载", Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(this, "未选中,不自动下载", Toast.LENGTH_SHORT).show();
}
}
public void contection(View v){
if (ConnectionUtils.isConnected(this))
{
if (ConnectionUtils.isWIFI(this))
{
Toast.makeText(this, "WIFI连接", Toast.LENGTH_SHORT).show();;
}
else if (ConnectionUtils.isMobile(this))
{
Toast.makeText(this, "移动网络连接", Toast.LENGTH_SHORT).show();;
}
}
else{
Toast.makeText(this, "网络未连接", Toast.LENGTH_SHORT).show();;
}
}
}
0 0
- 判断iphone网络状态
- 判断网络连接状态
- 判断网络在线状态
- android 判断网络状态
- Android判断网络状态
- Android 判断网络状态
- android 网络状态判断
- 判断网络连接状态
- 判断网络状态
- IOS~网络状态判断
- Android: 判断网络状态
- android 网络状态判断
- android 判断网络状态
- android判断网络状态
- android判断网络状态
- 判断网络状态
- android 判断网络状态
- 判断网络状态
- python课程学习第二课
- MySQL 字段的操作,修改指定字段内容
- Java集合框架认识
- 电脑开机过程
- vue全家桶
- 网络判断状态
- Git学习笔记
- 进程与线程
- leetcode104. Maximum Depth of Binary Tree
- 付诸行动,将三分热度,坚持到十分热度。
- 关于vue.js是什么,为什么要在nodejs中安装?
- 对多线程的理解
- ksoap2 出现java.io.EOFException 的问题
- vb:Cg色彩精灵第三部分: 部分重点代码分析