List of usage examples for android.net ConnectivityManager TYPE_MOBILE
int TYPE_MOBILE
To view the source code for android.net ConnectivityManager TYPE_MOBILE.
Click Source Link
From source file:com.inovex.zabbixmobile.push.NotificationService.java
private void logNotification(String status, String message, Long triggerid, String source) { // Logging incoming notifications for Debuggin // timestamp status message triggerid network try {/*w w w. java 2 s . c o m*/ File folder = new File(Environment.getExternalStorageDirectory() + "/zax"); boolean var = false; if (!folder.exists()) { var = folder.mkdir(); } final String filename = folder.toString() + "/" + "push_logs.csv"; File csv = new File(filename); if (!csv.exists() || !csv.isFile()) { csv.createNewFile(); } FileWriter fw = new FileWriter(csv, true); String date = Calendar.getInstance().getTime().toString(); fw.append(date); fw.append('\t'); fw.append(source); fw.append('\t'); fw.append(Long.toString(triggerid)); fw.append('\t'); fw.append(status); fw.append('\t'); fw.append(message); fw.append('\t'); ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); String net = null; switch (activeNetwork.getType()) { case ConnectivityManager.TYPE_WIFI: String ssid = ((WifiManager) getSystemService(WIFI_SERVICE)).getConnectionInfo().getSSID(); net = "wifi - ssid: " + ssid; break; case ConnectivityManager.TYPE_MOBILE: net = "mobile"; break; default: net = "other network type"; } fw.append(net); fw.append("\t\n"); fw.flush(); fw.close(); Log.d(TAG, "writing to logfile " + date + "" + source + " " + status + " " + message + " " + net); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.openhab.habdroid.ui.OpenHABWidgetListActivity.java
/** * This is called when activity is created. Initializes the state, performs network * state based selection for app initialization and starts the widget list *///from ww w . j ava 2 s . com @Override public void onCreate(Bundle savedInstanceState) { Log.d("OpenHABWidgetListActivity", "onCreate"); // Set default values, false means do it one time during the very first launch PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Set non-persistant HABDroid version preference to current version from application package try { PreferenceManager.getDefaultSharedPreferences(this).edit().putString("default_openhab_appversion", getPackageManager().getPackageInfo(getPackageName(), 0).versionName).commit(); } catch (NameNotFoundException e1) { if (e1 != null) Log.d(TAG, e1.getMessage()); } // Set the theme to one from preferences Util.setActivityTheme(this); // Fetch openHAB service type name from strings.xml openHABServiceType = getString(R.string.openhab_service_type); // Enable progress ring bar requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); requestWindowFeature(Window.FEATURE_PROGRESS); setProgressBarIndeterminateVisibility(true); // Initialize crittercism reporting JSONObject crittercismConfig = new JSONObject(); try { crittercismConfig.put("shouldCollectLogcat", true); } catch (JSONException e) { if (e.getMessage() != null) Log.e(TAG, e.getMessage()); else Log.e(TAG, "Crittercism JSON exception"); } Crittercism.init(getApplicationContext(), "5117659f59e1bd4ba9000004", crittercismConfig); // Initialize activity view super.onCreate(savedInstanceState); setContentView(R.layout.openhabwidgetlist); // Disable screen timeout if set in preferences SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); if (settings.getBoolean("default_openhab_screentimeroff", false)) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } // Check if we got all needed permissions PackageManager pm = getPackageManager(); if (!(pm.checkPermission(permission.CHANGE_WIFI_MULTICAST_STATE, getPackageName()) == PackageManager.PERMISSION_GRANTED)) { showAlertDialog(getString(R.string.erorr_no_wifi_mcast_permission)); serviceDiscoveryEnabled = false; } if (!(pm.checkPermission(permission.ACCESS_WIFI_STATE, getPackageName()) == PackageManager.PERMISSION_GRANTED)) { showAlertDialog(getString(R.string.erorr_no_wifi_state_permission)); serviceDiscoveryEnabled = false; } // Get username/password from preferences openHABUsername = settings.getString("default_openhab_username", null); openHABPassword = settings.getString("default_openhab_password", null); // Create new data source and adapter and set it to list view openHABWidgetDataSource = new OpenHABWidgetDataSource(); openHABWidgetAdapter = new OpenHABWidgetAdapter(OpenHABWidgetListActivity.this, R.layout.openhabwidgetlist_genericitem, widgetList); getListView().setAdapter(openHABWidgetAdapter); // Set adapter parameters openHABWidgetAdapter.setOpenHABUsername(openHABUsername); openHABWidgetAdapter.setOpenHABPassword(openHABPassword); // Enable app logo as home button this.getActionBar().setHomeButtonEnabled(true); // Check if we have openHAB page url in saved instance state? if (savedInstanceState != null) { displayPageUrl = savedInstanceState.getString("displayPageUrl"); openHABBaseUrl = savedInstanceState.getString("openHABBaseUrl"); sitemapRootUrl = savedInstanceState.getString("sitemapRootUrl"); openHABWidgetAdapter.setOpenHABBaseUrl(openHABBaseUrl); } // Check if this is a launch from myself (drill down navigation) if (getIntent() != null) { if (getIntent().getAction() != null) { if (getIntent().getAction().equals("org.openhab.habdroid.ui.OpwnHABWidgetListActivity")) { displayPageUrl = getIntent().getExtras().getString("displayPageUrl"); openHABBaseUrl = getIntent().getExtras().getString("openHABBaseUrl"); sitemapRootUrl = getIntent().getExtras().getString("sitemapRootUrl"); this.setTitle(getIntent().getExtras().getString("pageTitle")); openHABWidgetAdapter.setOpenHABBaseUrl(openHABBaseUrl); } } } // If yes, then just go to it (means restore activity from it's saved state) if (displayPageUrl.length() > 0) { Log.d(TAG, "displayPageUrl = " + displayPageUrl); showPage(displayPageUrl, false); // If not means it is a clean start } else { if (getIntent() != null) { Log.i(TAG, "Launch intent = " + getIntent().getAction()); // If this is a launch through NFC tag reading if (getIntent().getAction() != null) { if (getIntent().getAction().equals("android.nfc.action.NDEF_DISCOVERED")) { // Save url which we got from NFC tag nfcTagData = getIntent().getDataString(); } } } // If we are in demo mode, ignore all settings and use demo url from strings if (settings.getBoolean("default_openhab_demomode", false)) { openHABBaseUrl = getString(R.string.openhab_demo_url); Log.i(TAG, "Demo mode, connecting to " + openHABBaseUrl); Toast.makeText(getApplicationContext(), getString(R.string.info_demo_mode), Toast.LENGTH_LONG) .show(); showTime(); } else { openHABBaseUrl = normalizeUrl(settings.getString("default_openhab_url", "")); // Check if we have a direct URL in preferences, if yes - use it if (openHABBaseUrl.length() > 0) { Log.i(TAG, "Connecting to configured URL = " + openHABBaseUrl); Toast.makeText(getApplicationContext(), getString(R.string.info_conn_url), Toast.LENGTH_SHORT) .show(); showTime(); } else { // Get current network information ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetworkInfo != null) { Log.i(TAG, "Network is connected"); // If network is mobile, try to use remote URL if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE || serviceDiscoveryEnabled == false) { if (!serviceDiscoveryEnabled) { Log.i(TAG, "openHAB discovery is disabled"); } else { Log.i(TAG, "Network is Mobile (" + activeNetworkInfo.getSubtypeName() + ")"); } openHABBaseUrl = normalizeUrl(settings.getString("default_openhab_alturl", "")); // If remote URL is configured if (openHABBaseUrl.length() > 0) { Toast.makeText(getApplicationContext(), getString(R.string.info_conn_rem_url), Toast.LENGTH_SHORT).show(); Log.i(TAG, "Connecting to remote URL " + openHABBaseUrl); showTime(); } else { Toast.makeText(getApplicationContext(), getString(R.string.error_no_url), Toast.LENGTH_LONG).show(); } // If network is WiFi or Ethernet } if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI || activeNetworkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) { Log.i(TAG, "Network is WiFi or Ethernet"); // Start service discovery this.serviceResolver = new AsyncServiceResolver(this, openHABServiceType); progressDialog = ProgressDialog.show(this, "", "Discovering openHAB. Please wait...", true); this.serviceResolver.start(); // We don't know how to handle this network type } else { Log.i(TAG, "Network type (" + activeNetworkInfo.getTypeName() + ") is unsupported"); } // Network is not available } else { Log.i(TAG, "Network is not available"); Toast.makeText(getApplicationContext(), getString(R.string.error_network_not_available), Toast.LENGTH_LONG).show(); } } } } }
From source file:cx.ring.service.LocalService.java
@Override public void onCreate() { Log.e(TAG, "onCreate"); super.onCreate(); mediaManager = new MediaManager(this); notificationManager = NotificationManagerCompat.from(this); final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); final int cacheSize = maxMemory / 8; mMemoryCache = new LruCache<Long, Bitmap>(cacheSize) { @Override/*from w w w .j av a 2 s.com*/ protected int sizeOf(Long key, Bitmap bitmap) { return bitmap.getByteCount() / 1024; } }; historyManager = new HistoryManager(this); Intent intent = new Intent(this, DRingService.class); startService(intent); bindService(intent, mConnection, BIND_AUTO_CREATE | BIND_IMPORTANT | BIND_ABOVE_CLIENT); ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); isWifiConn = ni != null && ni.isConnected(); ni = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); isMobileConn = ni != null && ni.isConnected(); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); canUseContacts = sharedPreferences.getBoolean(SettingsFragment.KEY_PREF_CONTACTS, true); canUseMobile = sharedPreferences.getBoolean(SettingsFragment.KEY_PREF_MOBILE, true); sharedPreferences.registerOnSharedPreferenceChangeListener(this); }
From source file:com.android.tv.settings.about.AboutFragment.java
public static boolean isWifiOnly(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); return (!cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)); }
From source file:org.mozilla.gecko.sync.setup.activities.SetupSyncActivity.java
private boolean hasInternet() { Logger.debug(LOG_TAG, "Checking internet connectivity."); ConnectivityManager connManager = (ConnectivityManager) mContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mobile = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifi.isConnected() || mobile.isConnected()) { Logger.debug(LOG_TAG, "Internet connected."); return true; }/*w ww . j ava 2 s . c o m*/ return false; }
From source file:net.net76.lifeiq.TaskiQ.RegisterActivity.java
public boolean isNetworkAvaliable(Context ctx) { ConnectivityManager connectivityManager = (ConnectivityManager) ctx .getSystemService(Context.CONNECTIVITY_SERVICE); if ((connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) != null && connectivityManager .getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED) || (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI) != null && connectivityManager .getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED)) { return true; } else {//w ww . j a va2 s . co m return false; } }
From source file:com.starup.traven.travelkorea.ImageGridFragment.java
private void updateConnectedFlags() { ConnectivityManager connMgr = (ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeInfo = connMgr.getActiveNetworkInfo(); if (activeInfo != null && activeInfo.isConnected()) { wifiConnected = activeInfo.getType() == ConnectivityManager.TYPE_WIFI; mobileConnected = activeInfo.getType() == ConnectivityManager.TYPE_MOBILE; } else {//w w w .j av a2 s . c o m wifiConnected = false; mobileConnected = false; } }
From source file:com.iStudy.Study.Renren.Util.java
/** * ??/*from w w w . j a v a 2s .c om*/ * @param * Context * @return * true - ?3G/GSM?wifi * false - ?contextnull */ public static boolean isNetworkConnected(Context context) { if (context == null) { return false; } ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); State mobileState = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); State wifiState = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); if (mobileState == State.DISCONNECTED && wifiState == State.DISCONNECTED) { return false; } return true; }
From source file:com.cybrosys.currency.CurrencyMain.java
public final boolean isConnection() { @SuppressWarnings("static-access") ConnectivityManager cm = (ConnectivityManager) getActivity() .getSystemService(getActivity().CONNECTIVITY_SERVICE); NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiNetwork != null && wifiNetwork.isConnected()) { return true; }//from w w w . j a v a 2 s. co m NetworkInfo mobileNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobileNetwork != null && mobileNetwork.isConnected()) { return true; } NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork != null && activeNetwork.isConnected()) { return true; } return false; }
From source file:com.mattprecious.notisync.activity.MainActivity.java
private void setDefaults() { ConnectivityManager connec = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mobile = connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobile != null) { Preferences.setMode(this, Preferences.Mode.PRIMARY); } else {// w w w .j a v a 2 s .c o m Preferences.setMode(this, Preferences.Mode.SECONDARY); } Preferences.populateDefaults(this); }