短视频APP源码,检查网络状况相关的代码
public boolean checkNetworkInfo() {
ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
// mobile 3G Data Network
State mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
.getState();
// wifi
State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.getState();
// 如果3G网络和wifi网络都未连接,且不是处于正在连接状态 则进入Network Setting界面 由用户配置网络连接
if (mobile == State.CONNECTED || mobile == State.CONNECTING)
return true;
if (wifi == State.CONNECTED || wifi == State.CONNECTING)
return true;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getResources().getString(R.string.no_network))
.setCancelable(false)
.setPositiveButton(
getResources().getString(R.string.configuration),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// 进入无线网络配置界面
startActivity(new Intent(
Settings.ACTION_WIRELESS_SETTINGS));
MainActivity.this.finish();
}
})
.setNegativeButton(getResources().getString(R.string.quit),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MainActivity.this.finish();
}
});
builder.show();
return false;
}
以上就是短视频APP源码,检查网络状况相关的代码, 更多内容欢迎关注之后的文章