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:eg.edu.alexu.alexandriauniversity.activity.ChannelsActivity.java
private void doFirstTime() { //add channels first run only SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); boolean previouslyStarted = prefs.getBoolean(getString(R.string.pref_previously_started), false); if (!previouslyStarted) { //Check internet connection for now all times but next step will be first time only final ConnectivityManager connMgr = (ConnectivityManager) this .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.isAvailable() && wifi.isConnected()) { Toast.makeText(this, "Adding Feeds over WIFI", Toast.LENGTH_LONG).show(); addChannelFirstTime();// w w w . j a v a2s . c om SharedPreferences.Editor edit = prefs.edit(); edit.putBoolean(getString(R.string.pref_previously_started), Boolean.TRUE); edit.apply(); } else if (mobile.isAvailable() && mobile.isConnected()) { Toast.makeText(this, "Adding Feeds Over Mobile 3G ", Toast.LENGTH_LONG).show(); addChannelFirstTime(); SharedPreferences.Editor edit = prefs.edit(); edit.putBoolean(getString(R.string.pref_previously_started), Boolean.TRUE); edit.apply(); } else { Toast.makeText(this, "No Network WIFI/3G, Can't Add Feeds!", Toast.LENGTH_LONG).show(); SharedPreferences.Editor edit = prefs.edit(); edit.putBoolean(getString(R.string.pref_previously_started), Boolean.FALSE); edit.apply(); } } }
From source file:com.google.zxing.client.android.history.HistoryActivity.java
public boolean netWorkdisponibilidade(Context cont) { boolean conectado = false; ConnectivityManager conmag;// w ww . j a v a 2 s .c o m conmag = (ConnectivityManager) cont.getSystemService(Context.CONNECTIVITY_SERVICE); conmag.getActiveNetworkInfo(); // Verifica o WIFI if (conmag.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) { conectado = true; Toast.makeText(this, R.string.toast_is_net_wifi, Toast.LENGTH_LONG).show(); } // Verifica o 3G else if (conmag.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected()) { conectado = true; Toast.makeText(this, R.string.toast_is_net_3g, Toast.LENGTH_LONG).show(); } else { conectado = false; } return conectado; }
From source file:com.g_node.gca.abstracts.AbstractContentTabFragment.java
private void getAndUpdateAbstractFiguresBtn() { String getFiguresQuery = "SELECT * FROM ABSTRACT_FIGURES WHERE ABSTRACT_UUID = '" + value + "';"; Cursor absFiguresCursor = DatabaseHelper.database.rawQuery(getFiguresQuery, null); if (absFiguresCursor.getCount() > 0) { btnOpenAbstractFig.setText("Show Figures" + " (" + absFiguresCursor.getCount() + ")"); btnOpenAbstractFig.setOnClickListener(new OnClickListener() { @Override/*ww w .ja v a 2s.com*/ public void onClick(View arg0) { //if Internet is connected if (isNetworkAvailable()) { //check if interent is WIFI ConnectivityManager connManager = (ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mMobile = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mWifi.isConnected()) { //Toast.makeText(getActivity(), "Connected via WLAN", Toast.LENGTH_SHORT).show(); Intent figuresIntent = new Intent(getActivity(), AbstractFiguresActivity.class); figuresIntent.putExtra("abs_uuid", value); startActivity(figuresIntent); } else if (mMobile.isConnected()) { //if connected with mobile data - 2G, 3G, 4G etc //Toast.makeText(getActivity(), "Connected via Mobile Internet", Toast.LENGTH_SHORT).show(); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Additional Traffic Warning").setMessage( "Downloading of Figures over Mobile Internet may create additional Traffic. Do you want to Continue ?") .setPositiveButton("Continue", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if user Agrees to continue Intent figuresIntent = new Intent(getActivity(), AbstractFiguresActivity.class); figuresIntent.putExtra("abs_uuid", value); startActivity(figuresIntent); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // Handle Cancel dialog.cancel(); } }).setIcon(android.R.drawable.ic_dialog_alert).show(); } else { ; } //end if/else of wlan/mobile } else { Toast.makeText(getActivity(), "Not Connected to Internet - Please connect to Internet first", Toast.LENGTH_SHORT) .show(); } //end if/else of isNetworkAvailable } }); } else { btnOpenAbstractFig.setText("No Figures Found"); btnOpenAbstractFig.setEnabled(false); //btnOpenAbstractFig.setVisibility(View.GONE); } }
From source file:com.android.development.Connectivity.java
private void onCrash() { ConnectivityManager foo = null; foo.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, Phone.FEATURE_ENABLE_MMS); }
From source file:com.bbxiaoqu.api.util.Utils.java
/** * Proxy//from www . j a va2 s .co m */ public static HttpHost detectProxy(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni != null && ni.isAvailable() && ni.getType() == ConnectivityManager.TYPE_MOBILE) { String proxyHost = android.net.Proxy.getDefaultHost(); int port = android.net.Proxy.getDefaultPort(); if (proxyHost != null) { return new HttpHost(proxyHost, port, "http"); } } return null; }
From source file:com.chalmers.schmaps.GoogleMapSearchLocation.java
/** * Check if the device is connected to internet. * Need three if-statements because getActiveNetworkInfo() may return null * and end up with a force close. So thats the last thing to check. * @return true if there is an internet connection *//*from w ww . j a v a 2 s .c o m*/ public boolean gotInternetConnection() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiNetwork != null && wifiNetwork.isConnected()) { return true; } 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.android.providers.downloads.DownloadInfo.java
/** * Translate a ConnectivityManager.TYPE_* constant to the corresponding * DownloadManager.Request.NETWORK_* bit flag. *///w w w . j av a2 s . com private int translateNetworkTypeToApiFlag(int networkType) { switch (networkType) { case ConnectivityManager.TYPE_MOBILE: return DownloadManager.Request.NETWORK_MOBILE; case ConnectivityManager.TYPE_WIFI: return DownloadManager.Request.NETWORK_WIFI; case ConnectivityManager.TYPE_BLUETOOTH: return DownloadManager.Request.NETWORK_BLUETOOTH; default: return 0; } }
From source file:com.ubuntuone.android.files.activity.FilesActivity.java
/** * This dialog applies to downloading directories only. * // w ww. j a v a2 s . c o m * @param extras * @return */ private Dialog buildDownloadDialog(final Bundle extras) { final String resourcePath = extras.getString(MetaService.EXTRA_RESOURCE_PATH); final long size = extras.getLong(MetaService.EXTRA_SIZE); final String sizeText = FileUtilities.getHumanReadableSize(size); final long free = StorageActivity.getAvailableExternalStorageSize(); if (free < size) { return buildInsufficientSpaceDialog(size, free); } final StringBuilder msgBuilder = new StringBuilder(32); msgBuilder.append(String.format(getString(R.string.dialog_downloading_dir_is_x_large), sizeText)); int network = NetworkUtil.getAvailableNetworkType(this); if (network == -1) { return buildNoNetworkDialog(); } else if (network == ConnectivityManager.TYPE_MOBILE) { msgBuilder.append(" "); msgBuilder.append(getString(R.string.dialog_downloading_dir_on_mobile)); } msgBuilder.append(" "); msgBuilder.append(getString(R.string.dialog_downloading_dir_are_you_sure)); final OnClickListener onClick = new OnClickListener() { private void download() { UpDownServiceHelper.download(FilesActivity.this, resourcePath); } public void onClick(DialogInterface dialog, int which) { switch (which) { case Dialog.BUTTON_POSITIVE: download(); break; case Dialog.BUTTON_NEGATIVE: // Will dismiss below. break; default: Log.e(TAG, "no such button"); break; } removeDialog(DIALOG_DOWNLOAD_ID); } }; final AlertDialog dialog = new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_info) .setTitle(R.string.dialog_downloading_dir_title).setMessage(msgBuilder.toString()) .setPositiveButton(R.string.yes, onClick).setNegativeButton(R.string.no, onClick).create(); return dialog; }
From source file:com.roamprocess1.roaming4world.syncadapter.SyncAdapter.java
public static int getConnectivityStatus(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (null != activeNetwork) { if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) return SipHome.TYPE_WIFI; if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) return SipHome.TYPE_MOBILE; }/* w ww . j a va 2 s . co m*/ return SipHome.TYPE_NOT_CONNECTED; }
From source file:org.pidome.client.services.aidl.service.SystemServiceAidl.java
private void setHome() { if (prefs != null) { if (prefs.getBoolPreference("wifiConnectHomeEnabled", false)) { ConnectivityManager connManager = (ConnectivityManager) getSystemService( Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connManager.getActiveNetworkInfo(); if (networkInfo.isConnected() && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); final WifiInfo connectionInfo = wifiManager.getConnectionInfo(); if (connectionInfo != null) { String SSID = connectionInfo.getSSID(); String BSSID = connectionInfo.getBSSID(); if (SSID != null && BSSID != null) { if (SSID.equals(prefs.getStringPreference("wifiConnectSSID", java.util.UUID.randomUUID().toString())) && BSSID.equals(prefs.getStringPreference("wifiConnectBSSID", java.util.UUID.randomUUID().toString()))) { singleThreadfPipeExecutor.execute((Runnable) () -> { int i = SystemServiceAidl.this.clientCallBackList.beginBroadcast(); while (i > 0) { i--; try { clientCallBackList.beginBroadcast(); clientCallBackList.getBroadcastItem(i).updateUserPresence(1); clientCallBackList.finishBroadcast(); } catch (RemoteException ex) { Logger.getLogger(SystemServiceAidl.class.getName()).log(Level.SEVERE, null, ex); }//from w ww . ja v a 2s .c om } }); localizationService.setHome(true); } else { localizationService.setHome(false); } } } } else if (networkInfo.isConnected() && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { localizationService.setHome(false); } } } }