List of usage examples for android.net ConnectivityManager getBackgroundDataSetting
@Deprecated public boolean getBackgroundDataSetting()
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); return cm.getBackgroundDataSetting() && cm.getActiveNetworkInfo() != null; }
From source file:Main.java
public static boolean isWifi(Context context) { ConnectivityManager mConnectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = mConnectivity.getActiveNetworkInfo(); if (netInfo == null || !mConnectivity.getBackgroundDataSetting()) { return false; } else if (ConnectivityManager.TYPE_WIFI == netInfo.getType()) { return netInfo.isConnected(); } else {/*w w w .ja v a 2 s . co m*/ return false; } }
From source file:Main.java
public static boolean isConnect(Context context) { ConnectivityManager mConnectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE); // check if connect NetworkInfo netInfo = mConnectivity.getActiveNetworkInfo(); if (netInfo == null || !mConnectivity.getBackgroundDataSetting()) { return false; } else {// ww w.java 2s .c o m return true; } }
From source file:com.AA.Other.RSSParse.java
/** * Check if the network is available for get the RSS feed * @param isBackground if the request is being run in the background * @param callingContext current application context * @return if the network is in a state where a request can be sent *///w w w .ja v a 2 s .c o m private static boolean isNetworkAvailable(boolean isBackground, Context callingContext) { ConnectivityManager manager = (ConnectivityManager) callingContext .getSystemService(Context.CONNECTIVITY_SERVICE); //If the request is in the background and the phone does not want us to do //any background data transfer then respect that wish and bail. if (isBackground && !manager.getBackgroundDataSetting()) return false; //if the current connection isn't ready for data then bail //Apparently if there is no network, the network info returns null NetworkInfo netInfo = manager.getActiveNetworkInfo(); if (netInfo == null || manager.getActiveNetworkInfo().getState() != NetworkInfo.State.CONNECTED) return false; return true; }
From source file:org.kontalk.util.SystemUtils.java
/** Checks for network availability. */ public static boolean isNetworkConnectionAvailable(Context context) { final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getBackgroundDataSetting()) { NetworkInfo info = cm.getActiveNetworkInfo(); if (info != null && info.getState() == NetworkInfo.State.CONNECTED) return true; }/*w w w . jav a2 s . c o m*/ return false; }
From source file:org.transdroid.service.UpdateService.java
@Override protected void onHandleIntent(Intent intent) { // Check if the user has background data disabled ConnectivityManager conn = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); if (!conn.getBackgroundDataSetting()) { TLog.d(LOG_NAME,/*from w ww .j a va 2 s .c o m*/ "Skip checking for new app versions, since background data is disabled on a system-wide level"); return; } // Check if the update service should run SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); AlarmSettings settings = Preferences.readAlarmSettings(prefs); if (!settings.shouldCheckForUpdates()) { TLog.d(LOG_NAME, "The user disabled the update checker service."); return; } DefaultHttpClient httpclient = new DefaultHttpClient(); try { // Retrieve what is the latest released app and search module versions String[] app = retrieveLatestVersion(httpclient, LATEST_URL_APP); String[] search = retrieveLatestVersion(httpclient, LATEST_URL_SEARCH); int appVersion = Integer.parseInt(app[0].trim()); int searchVersion = Integer.parseInt(search[0].trim()); // New version of the app? try { PackageInfo appPackage = getPackageManager().getPackageInfo(PACKAGE_APP, 0); if (appPackage.versionCode < appVersion) { // New version available! Notify the user. newNotification(getString(R.string.update_app_newversion), getString(R.string.update_app_newversion), getString(R.string.update_updateto, app[1].trim()), DOWNLOAD_URL_APP + "?" + Integer.toString(random.nextInt()), 0); } } catch (NameNotFoundException e) { // Not installed... this can never happen since this Service is part of the app itself. } // New version of the search module? try { PackageInfo searchPackage = getPackageManager().getPackageInfo(PACKAGE_SEARCH, 0); if (searchPackage.versionCode < searchVersion) { // New version available! Notify the user. newNotification(getString(R.string.update_search_newversion), getString(R.string.update_search_newversion), getString(R.string.update_updateto, search[1].trim()), DOWNLOAD_URL_SEARCH + "?" + Integer.toString(random.nextInt()), 0); } } catch (NameNotFoundException e) { // The search module isn't installed yet at all; ignore and wait for the user to manually // install it (when the first search is initiated) } } catch (Exception e) { // Cannot check right now for some reason; log and `ignore TLog.d(LOG_NAME, "Cannot retrieve latest app or search module version code from the site: " + e.toString()); } }
From source file:biz.shadowservices.DegreesToolbox.DataFetcher.java
public boolean isBackgroundDataEnabled(Context context) { ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); return (mgr.getBackgroundDataSetting()); }
From source file:com.achow101.bitcointalkforum.NotificationService.java
private void handleIntent(Intent intent) { // obtain the wake lock PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "NotificationService"); mWakeLock.acquire();//from ww w.j a v a 2 s. c o m // get sessid and username from intent String sessId = intent.getStringExtra("SESSION ID"); String mUsername = intent.getStringExtra("Username"); // check the global background data setting ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); if (!cm.getBackgroundDataSetting()) { stopSelf(); return; } // Get preferences SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); // Check that notifications are wanted boolean getNotifs = prefs.getBoolean("notifications_new_message", true); // do stuff if notifications are wanted if (getNotifs) { // get remaining booleans boolean getWatchlist = prefs.getBoolean("notifications_watchlist", true); boolean getUnreadposts = prefs.getBoolean("notifications_unreadposts", false); boolean getUnreadreplies = prefs.getBoolean("notifications_unreadreplies", false); boolean getMessages = prefs.getBoolean("notifications_messages", true); // Get notification settings stuff sound = prefs.getString("notifications_new_message_ringtone", "content://settings/system/notification_sound"); vibrate = prefs.getBoolean("notifications_new_message_vibrate", true); // do the actual work, in a separate thread new PollTask(getWatchlist, getUnreadposts, getUnreadreplies, getMessages, sessId, mUsername).execute(); } }
From source file:com.ebridgevas.android.ebridgeapp.messaging.mqttservice.MqttService.java
@SuppressWarnings("deprecation") private void registerBroadcastReceivers() { if (networkConnectionMonitor == null) { networkConnectionMonitor = new NetworkConnectionIntentReceiver(); registerReceiver(networkConnectionMonitor, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); }/*from w ww .java 2 s .c om*/ if (Build.VERSION.SDK_INT < 14 /**Build.VERSION_CODES.ICE_CREAM_SANDWICH**/ ) { // Support the old system for background data preferences ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); backgroundDataEnabled = cm.getBackgroundDataSetting(); if (backgroundDataPreferenceMonitor == null) { backgroundDataPreferenceMonitor = new BackgroundDataPreferenceReceiver(); registerReceiver(backgroundDataPreferenceMonitor, new IntentFilter(ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED)); } } }
From source file:com.android.exchange.SyncManager.java
public void run() { sStop = false;// www . ja va2 s .co m alwaysLog("!!! SyncManager thread running"); // If we're really debugging, turn on all logging if (Eas.DEBUG) { Eas.USER_LOG = true; Eas.PARSER_LOG = true; Eas.FILE_LOG = true; } // If we need to wait for the debugger, do so if (Eas.WAIT_DEBUG) { Debug.waitForDebugger(); } // Synchronize here to prevent a shutdown from happening while we initialize our observers // and receivers synchronized (sSyncLock) { if (INSTANCE != null) { mResolver = getContentResolver(); // Set up our observers; we need them to know when to start/stop various syncs based // on the insert/delete/update of mailboxes and accounts // We also observe synced messages to trigger upsyncs at the appropriate time mAccountObserver = new AccountObserver(mHandler); mResolver.registerContentObserver(Account.CONTENT_URI, true, mAccountObserver); mMailboxObserver = new MailboxObserver(mHandler); mResolver.registerContentObserver(Mailbox.CONTENT_URI, false, mMailboxObserver); mSyncedMessageObserver = new SyncedMessageObserver(mHandler); mResolver.registerContentObserver(Message.SYNCED_CONTENT_URI, true, mSyncedMessageObserver); mMessageObserver = new MessageObserver(mHandler); mResolver.registerContentObserver(Message.CONTENT_URI, true, mMessageObserver); mSyncStatusObserver = new EasSyncStatusObserver(); mStatusChangeListener = ContentResolver .addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, mSyncStatusObserver); // Set up our observer for AccountManager mAccountsUpdatedListener = new EasAccountsUpdatedListener(); AccountManager.get(getApplication()).addOnAccountsUpdatedListener(mAccountsUpdatedListener, mHandler, true); // Set up receivers for connectivity and background data setting mConnectivityReceiver = new ConnectivityReceiver(); registerReceiver(mConnectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); mBackgroundDataSettingReceiver = new ConnectivityReceiver(); registerReceiver(mBackgroundDataSettingReceiver, new IntentFilter(ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED)); // Save away the current background data setting; we'll keep track of it with the // receiver we just registered ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); mBackgroundData = cm.getBackgroundDataSetting(); // See if any settings have changed while we weren't running... checkPIMSyncSettings(); } } try { // Loop indefinitely until we're shut down while (!sStop) { runAwake(SYNC_MANAGER_ID); waitForConnectivity(); mNextWaitReason = "Heartbeat"; long nextWait = checkMailboxes(); try { synchronized (this) { if (!mKicked) { if (nextWait < 0) { log("Negative wait? Setting to 1s"); nextWait = 1 * SECONDS; } if (nextWait > 10 * SECONDS) { log("Next awake in " + nextWait / 1000 + "s: " + mNextWaitReason); runAsleep(SYNC_MANAGER_ID, nextWait + (3 * SECONDS)); } wait(nextWait); } } } catch (InterruptedException e) { // Needs to be caught, but causes no problem log("SyncManager interrupted"); } finally { synchronized (this) { if (mKicked) { //log("Wait deferred due to kick"); mKicked = false; } } } } log("Shutdown requested"); } catch (RuntimeException e) { Log.e(TAG, "RuntimeException in SyncManager", e); throw e; } finally { shutdown(); } }