List of usage examples for android.net ConnectivityManager getNetworkInfo
@Deprecated
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@Nullable
public NetworkInfo getNetworkInfo(@Nullable Network network)
From source file:ua.mkh.weather.MainActivity.java
public boolean low_mode_check() { boolean state = true; boolean state_brightness = true; boolean state_wifi = true; boolean state_bt = true; int status = Settings.System.getInt(getContentResolver(), "screen_brightness_mode", 0); if (status == 1) { state_brightness = false;//ww w . ja v a 2 s .c o m } //0 // ContentResolver cResolver = getContentResolver(); int brightness = 0; try { //Get the current system brightness brightness = System.getInt(cResolver, System.SCREEN_BRIGHTNESS); } catch (SettingNotFoundException e) { //Throw an error case it couldn't be retrieved Log.e("Error", "Cannot access system brightness"); e.printStackTrace(); } if (brightness > 25) { state_brightness = false; } //WIFI ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (wifi.isWifiEnabled()) { if (mWifi.isConnected()) { } else { state_wifi = false; } } //Bluetooth BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter.isEnabled()) { state_bt = false; } if (state_brightness == false || state_wifi == false || state_bt == false) { state = false; } return state; }
From source file:au.org.intersect.faims.android.ui.activity.ShowModuleActivity.java
private void setupWifiBroadcast() { broadcastReceiver = new WifiBroadcastReceiver(ShowModuleActivity.this); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION); registerReceiver(broadcastReceiver, intentFilter); ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); // initialize wifi connection state if (mWifi != null && mWifi.isConnected()) { wifiConnected = true;//from w w w. ja v a 2s . c o m } }
From source file:com.juick.android.MainActivity.java
private void maybeSendUsageReport() { if (usageReportThread != null) return;// w ww.ja v a 2s. c om String sendStats = sp.getString("usage_statistics", "no"); if (!sendStats.equals("send") && !sendStats.equals("send_wifi")) return; long last_usage_sent = sp.getLong("last_usage_sent", 0); if (last_usage_sent == 0) { sp.edit().putLong("last_usage_sent", System.currentTimeMillis()).commit(); return; } if (System.currentTimeMillis() - last_usage_sent > WhatsNew.REPORT_SEND_PERIOD) { ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (sendStats.equals("send_wifi") && !wifi.isConnected()) return; usageReportThread = new Thread() { @Override public void run() { new WhatsNew(MainActivity.this).reportUsage(); } }; usageReportThread.start(); } }
From source file:com.mobiletin.inputmethod.indic.LatinIME.java
public boolean isInternetOn() { // get Connectivity Manager object to check connection ConnectivityManager connec = (ConnectivityManager) getSystemService(getBaseContext().CONNECTIVITY_SERVICE); // Check for network connections if (connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED || connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING || connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING || connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED) { return true; } else if (connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED || connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED) { return false; }/*from w w w.ja va 2 s . c om*/ return false; }
From source file:com.android.mms.ui.MessageUtils.java
public static boolean isWifiConnected(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); MmsLog.d(TAG, "wifi state:" + wifiManager.getWifiState() + "wifi connected:" + wifi.isConnected()); if (wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED && wifi.isConnected()) { MmsLog.d(TAG, "Wifi connected"); return true; }// w ww. ja va 2s. co m MmsLog.d(TAG, "Wifi off or not connected"); return false; }
From source file:org.uguess.android.sysinfo.SiragonManager.java
@Override public boolean onOptionsItemSelected(MenuItem item) { final Activity ctx = getActivity(); if (item.getItemId() == MI_PREFERENCE) { Intent it = new Intent(ctx, InfoSettings.class); it.putExtra(PREF_KEY_SHOW_INFO_ICON, Util.getBooleanOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_SHOW_INFO_ICON)); it.putExtra(PREF_KEY_SHOW_TASK_ICON, Util.getBooleanOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_SHOW_TASK_ICON)); it.putExtra(PREF_KEY_AUTO_START_ICON, Util.getBooleanOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_AUTO_START_ICON, false)); it.putExtra(PREF_KEY_DEFAULT_SERVER, Util.getStringOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_DEFAULT_SERVER, null)); it.putExtra(PREF_KEY_DEFAULT_EMAIL, Util.getStringOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_DEFAULT_EMAIL, null)); it.putExtra(PREF_KEY_DEFAULT_TAB, Util.getIntOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_DEFAULT_TAB, 0)); it.putExtra(PREF_KEY_WIDGET_DISABLED, Util.getStringOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_WIDGET_DISABLED, null)); startActivityForResult(it, 2);/*from w w w . j a va 2 s . c o m*/ return true; } else if (item.getItemId() == MI_HELP) { Intent it = new Intent(Intent.ACTION_VIEW); String target = "http://www.siragon.com.ve"; //$NON-NLS-1$ ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (info != null && info.isConnected()) { target = "http://www.siragon.com.ve"; //$NON-NLS-1$ } it.setData(Uri.parse(target)); it = Intent.createChooser(it, null); startActivity(it); return true; } ///////////////////////PATH SERVER/////////////////////////////////// else if (item.getItemId() == MI_ABOUT) { ScrollView sv = new ScrollView(ctx); TextView txt = new TextView(ctx); txt.setGravity(Gravity.CENTER_HORIZONTAL); txt.setTextAppearance(ctx, android.R.style.TextAppearance_Medium); sv.addView(txt); String href = "http://www.google.com.ve"; //$NON-NLS-1$ txt.setText(Html.fromHtml(getString(R.string.about_msg, getVersionName(ctx.getPackageManager(), ctx.getPackageName()), href))); txt.setMovementMethod(LinkMovementMethod.getInstance()); new AlertDialog.Builder(ctx).setTitle(R.string.app_name).setIcon(R.drawable.logo2).setView(sv) .setNegativeButton(R.string.close, null).create().show(); return true; } else if (item.getItemId() == MI_EXIT) { OnClickListener listener = new OnClickListener() { public void onClick(DialogInterface dialog, int which) { Util.killSelf(handler, ctx, (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE), ctx.getPackageName()); } }; new AlertDialog.Builder(ctx).setTitle(R.string.prompt).setMessage(R.string.exit_prompt) .setPositiveButton(android.R.string.yes, listener).setNegativeButton(android.R.string.no, null) .create().show(); return true; } else if (item.getItemId() == MI_REFRESH) { updateInfo(); return true; } return false; }