use of android.net.NetworkInfo in project Android by hmkcode.
the class MainActivity method isConnected.
public boolean isConnected() {
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected())
return true;
else
return false;
}
use of android.net.NetworkInfo in project packer-ng-plugin by mcxiaoke.
the class MainActivity method addNetworkInfoSection.
private void addNetworkInfoSection() {
StringBuilder builder = new StringBuilder();
builder.append("[Network]\n");
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
if (info != null) {
builder.append(info);
}
builder.append("\n\n");
addSection(builder.toString());
}
use of android.net.NetworkInfo in project LollipopShowcase by mikepenz.
the class Network method isAvailiable.
public static boolean isAvailiable(Context ctx) {
ConnectivityManager conMgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo i = conMgr.getActiveNetworkInfo();
if (i == null)
return false;
if (!i.isConnected())
return false;
if (!i.isAvailable())
return false;
return true;
}
use of android.net.NetworkInfo in project qksms by moezbhatti.
the class Transaction method sendMMS.
private void sendMMS(final byte[] bytesToSend) {
revokeWifi(true);
// enable mms connection to mobile data
mConnMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
int result = beginMmsConnectivity();
if (LOCAL_LOGV)
Log.v(TAG, "result of connectivity: " + result + " ");
if (result != 0) {
// if mms feature is not already running (most likely isn't...) then register a receiver and wait for it to be active
IntentFilter filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context1, Intent intent) {
String action = intent.getAction();
if (!action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
return;
}
@SuppressWarnings("deprecation") NetworkInfo mNetworkInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
if ((mNetworkInfo == null) || (mNetworkInfo.getType() != ConnectivityManager.TYPE_MOBILE)) {
return;
}
if (!mNetworkInfo.isConnected()) {
return;
} else {
// ready to send the message now
if (LOCAL_LOGV)
Log.v(TAG, "sending through broadcast receiver");
alreadySending = true;
sendData(bytesToSend);
context.unregisterReceiver(this);
}
}
};
context.registerReceiver(receiver, filter);
try {
Looper.prepare();
} catch (Exception e) {
// Already on UI thread probably
}
// try sending after 3 seconds anyways if for some reason the receiver doesn't work
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (!alreadySending) {
try {
if (LOCAL_LOGV)
Log.v(TAG, "sending through handler");
context.unregisterReceiver(receiver);
} catch (Exception e) {
}
sendData(bytesToSend);
}
}
}, 7000);
} else {
// mms connection already active, so send the message
if (LOCAL_LOGV)
Log.v(TAG, "sending right away, already ready");
sendData(bytesToSend);
}
}
use of android.net.NetworkInfo in project nmid-headline by miao1007.
the class NetworkUtils method isNetworkAvailable.
public boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null;
}
Aggregations