Reputation: 575
i modify my last code but this code still show network found i disbale my network but is againshow network show if i disbale network connection is stil show toast other Connection Found i dont know y polease help me
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();
}
});
}}
Upvotes: 0
Views: 79
Reputation: 3025
Try this:
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();
}
Upvotes: 1
Reputation: 1110
You can try something like this :-
Get below permission in your android manifest-
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Have a broadcast receiver with below action in intent filter -
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
In the onReceive method of the receiver use below code :-
@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();
}
}
}
Upvotes: 0