android - mobiletype如果禁用 netwok,则总是显示网络

  显示原文与译文双语对照的内容
0 0

i modify的代码但仍然显示network网络show但is网络显示disbale网络连接 toast other other other other other other other help

final ConnectivityManager connMgr = (ConnectivityManager) 
 getSystemService(Context.CONNECTIVITY_SERVICE);
 final android.net.NetworkInfo mobile1 = 
 connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
 if (mobile1.isAvailable()) {
 Toast.makeText(LoginScreen.this," other Connection Found 
",Toast.LENGTH_LONG).show();
 btnLogin.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
String pinemptycheck = pin.getText().toString();
String mobileemptycheck = mobile.getText().toString();
 if (pinemptycheck.trim().equals("")||(mobileemptycheck.trim().equals("")))
 {
 Toast.makeText(getApplicationContext(),"Please Enter Correct Information", 
 Toast.LENGTH_LONG).show();
 } 
 else
 {
showProgress();
postLoginData();
 }
 }
 });
}
 else if (!mobile1.isAvailable()) {
Toast.makeText(LoginScreen.this,"No other Connection Found",Toast.LENGTH_LONG).show();
 btnLogin.setOnClickListener(new OnClickListener() {
 public void onClick(View v)
 {
 Toast.makeText(LoginScreen.this," No other Connection Found", Toast.LENGTH_LONG).show();
 }
 });
 }} 
时间:原作者:7个回答

0 0

尝试这个:

final ConnectivityManager connMgr = (ConnectivityManager) 
 getSystemService(Context.CONNECTIVITY_SERVICE);
 final android.net.NetworkInfo mobile1 = 
 connMgr.getActiveNetworkInfo();
 if (mobile1!= null && mobile1.isConnected() && mobile1.isAvailable() && (mobile1.getType() == ConnectivityManager.TYPE_MOBILE)) {
 Toast.makeText(CheckBoxTest.this," other Connection Found",Toast.LENGTH_LONG).show();
 }
原作者:
0 0

你可以试试这样的东西:-

在你的android清单中获得以下权限-

 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

在 Intent 过滤器中有一个带以下动作的广播接收器-

 <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>

在接收方的onReceive方法中使用以下代码:-

@Override
public void onReceive(Context context, Intent intent) {
 super.onReceive(context, intent);
if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
 final ConnectivityManager connMgr = (ConnectivityManager) context
. getSystemService(Context.CONNECTIVITY_SERVICE);
 final android.net.NetworkInfo wifi = connMgr
. getNetworkInfo(ConnectivityManager.TYPE_WIFI);
 final android.net.NetworkInfo mobile = connMgr
. getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
 if (wifi.isConnected() || mobile.isConnected()) {
 Toast.makeText(LoginScreen.this," other Connection Found 
",Toast.LENGTH_LONG).show();
 }
else
{
Toast.makeText(LoginScreen.this,"No other Connection Found",Toast.LENGTH_LONG).show();
}
 }

%7D

原作者:
...