List of usage examples for android.net ConnectivityManager CONNECTIVITY_ACTION
String CONNECTIVITY_ACTION
To view the source code for android.net ConnectivityManager CONNECTIVITY_ACTION.
Click Source Link
From source file:com.hao.common.manager.AppManager.java
private AppManager() { // ?//from www . j a v a 2 s.c o m CrashHandler.getInstance().init(); sApp.registerReceiver(new BroadcastReceiver() { private boolean mIsFirstReceiveBroadcast = true; @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { if (!mIsFirstReceiveBroadcast) { if (NetWorkUtil.isNetworkAvailable()) { RxBus.send(new RxEvent.NetworkConnectedEvent()); } else { RxBus.send(new RxEvent.NetworkDisconnectedEvent()); } } else { mIsFirstReceiveBroadcast = false; } } } }, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); }
From source file:com.google.android.apps.muzei.MuzeiWallpaperService.java
private void initialize() { FirebaseAnalytics.getInstance(this).setUserProperty("device_type", BuildConfig.DEVICE_TYPE); SourceManager.subscribeToSelectedSource(MuzeiWallpaperService.this); mNetworkChangeReceiver = new NetworkChangeReceiver(); IntentFilter networkChangeFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(mNetworkChangeReceiver, networkChangeFilter); // Ensure we retry loading the artwork if the network changed while the wallpaper was disabled ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( Context.CONNECTIVITY_SERVICE); Intent retryIntent = TaskQueueService.maybeRetryDownloadDueToGainedConnectivity(this); if (retryIntent != null && connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isConnected()) { startService(retryIntent);//w w w . ja va 2 s . c o m } // Set up a thread to update notifications whenever the artwork changes mNotificationHandlerThread = new HandlerThread("MuzeiWallpaperService-Notification"); mNotificationHandlerThread.start(); mNotificationContentObserver = new ContentObserver(new Handler(mNotificationHandlerThread.getLooper())) { @Override public void onChange(final boolean selfChange, final Uri uri) { NewWallpaperNotificationReceiver.maybeShowNewArtworkNotification(MuzeiWallpaperService.this); } }; getContentResolver().registerContentObserver(MuzeiContract.Artwork.CONTENT_URI, true, mNotificationContentObserver); // Set up a thread to update Android Wear whenever the artwork changes mWearableHandlerThread = new HandlerThread("MuzeiWallpaperService-Wearable"); mWearableHandlerThread.start(); mWearableContentObserver = new ContentObserver(new Handler(mWearableHandlerThread.getLooper())) { @Override public void onChange(final boolean selfChange, final Uri uri) { WearableController.updateArtwork(MuzeiWallpaperService.this); } }; getContentResolver().registerContentObserver(MuzeiContract.Artwork.CONTENT_URI, true, mWearableContentObserver); // Set up a thread to update the Artwork Info shortcut whenever the artwork changes if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { mArtworkInfoShortcutHandlerThread = new HandlerThread("MuzeiWallpaperService-ArtworkInfoShortcut"); mArtworkInfoShortcutHandlerThread.start(); mArtworkInfoShortcutContentObserver = new ContentObserver( new Handler(mArtworkInfoShortcutHandlerThread.getLooper())) { @RequiresApi(api = Build.VERSION_CODES.N_MR1) @Override public void onChange(final boolean selfChange, final Uri uri) { ArtworkInfoShortcutController.updateShortcut(MuzeiWallpaperService.this); } }; getContentResolver().registerContentObserver(MuzeiContract.Artwork.CONTENT_URI, true, mArtworkInfoShortcutContentObserver); } mInitialized = true; }
From source file:org.gateshipone.malp.application.artworkdatabase.BulkDownloadService.java
/** * Called when the service is created because it is requested by an activity *//*from w w w. ja v a 2s .c o m*/ @Override public void onCreate() { super.onCreate(); mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); if (null == mConnectionHandler) { mConnectionHandler = new ConnectionStateHandler(this); Log.v(TAG, "Registering connection state listener"); MPDQueryHandler.registerConnectionStateListener(mConnectionHandler); } if (null == mProfileManager) { mProfileManager = new MPDProfileManager(getApplicationContext()); } mSumImageDownloads = 0; mConnectionStateChangeReceiver = new ConnectionStateReceiver(); IntentFilter filter = new IntentFilter(); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(mConnectionStateChangeReceiver, filter); }
From source file:com.imgtec.hobbyist.fragments.loginsignup.LogInFragment.java
@Override public void onResume() { super.onResume(); connectionReceiver = new ConnectivityReceiver(); wifiUtil = new WifiUtil(getActivity()); getActivity().registerReceiver(connectionReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); reinitialization();//from w ww .ja va 2 s . c o m }
From source file:nu.firetech.android.pactrack.backend.ParcelUpdater.java
private void registerConnectionListener(Context ctx) { synchronized (sLock) { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); ctx.registerReceiver(this, intentFilter); sWaitingForDataConnection = true; }//from ww w. ja v a 2 s .co m }
From source file:net.sf.aria2.Aria2Service.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (isRunning()) throw new IllegalStateException("Can not start aria2: running instance already exists!"); unregisterOldReceiver();/*from ww w. ja v a 2s.c o m*/ final ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); final NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni != null && ni.isConnectedOrConnecting()) startAria2(Config.from(intent)); else { if (intent.hasExtra(Config.EXTRA_INTERACTIVE)) Toast.makeText(getApplicationContext(), getText(R.string.will_start_later), Toast.LENGTH_LONG) .show(); else { receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.hasExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY) && intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)) return; startAria2(Config.from(intent)); unregisterReceiver(this); receiver = null; } }; registerReceiver(receiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); } } return super.onStartCommand(intent, flags, startId); }
From source file:io.rapidpro.androidchannel.RapidPro.java
@Override public void onCreate() { super.onCreate(); PreferenceManager.setDefaultValues(this, R.layout.settings, false); // earlier versions of android are allowed to have higher message throughput // before Build.VERSION_CODES.ICE_CREAM_SANDWICH which is 14 if (Build.VERSION.SDK_INT < 14) { MESSAGE_THROTTLE = 100;// w w w . j a v a 2 s. c o m MESSAGE_THROTTLE_MINUTES = 60; MESSAGE_THROTTLE_WINDOW = 1000 * 60 * (MESSAGE_THROTTLE_MINUTES + 2); } s_this = this; // register our sms modem m_modem = new SMSModem(this, new SMSListener()); // register our Incoming SMS listener m_incomingSMSObserver = new IncomingSMSObserver(); getContentResolver().registerContentObserver(Uri.parse("content://sms"), true, m_incomingSMSObserver); // register our call listener m_callObserver = new CallObserver(); getContentResolver().registerContentObserver(Calls.CONTENT_URI, true, m_callObserver); // register for device details IntentFilter statusChanged = new IntentFilter(); statusChanged.addAction(Intent.ACTION_BATTERY_CHANGED); statusChanged.addAction(ConnectivityManager.CONNECTIVITY_ACTION); StatusReceiver receiver = new StatusReceiver(); getBaseContext().registerReceiver(receiver, statusChanged); WakefulIntentService.cancelAlarms(this); WakefulIntentService.scheduleAlarms(new RapidProAlarmListener(), this); refreshInstalledPacks(); updateNotification(); }
From source file:etsii_upm.obdii.EnviarService.java
@Override public void onCreate() { super.onCreate(); // Suscribe el BroadcastReceiver que instanciamos previamente a los // eventos relacionados con Internet que queremos controlar mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); iFiltro = new IntentFilter(); iFiltro.addAction(ConnectivityManager.CONNECTIVITY_ACTION); iReceiver = new iBroadcastR(); this.registerReceiver(iReceiver, iFiltro); //Inicializamos el thread de envio mHandler = new threadHandler(); enviarThread = new EnviarThread(mHandler); }
From source file:com.trellmor.berrymotes.sync.EmoteDownloader.java
public void start(SyncResult syncResult) { Log.info("EmoteDownload started"); this.updateNetworkInfo(); mSyncResult = syncResult;/*from w w w . j a va2 s . c om*/ if (!mIsConnected) { Log.error("Network not available"); syncResult.stats.numIoExceptions++; return; } // Registers BroadcastReceiver to track network connection changes. IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); NetworkReceiver receiver = new NetworkReceiver(); mContext.registerReceiver(receiver, filter); ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT); mHttpClient = AndroidHttpClient.newInstance(USER_AGENT); try { String[] subreddits = getSubreddits(); for (String subreddit : subreddits) { if (mSubreddits.isChecked(subreddit)) { Runnable subredditEmoteDownloader = new SubredditEmoteDownloader(mContext, this, subreddit); executor.execute(subredditEmoteDownloader); } else { // Delete this subreddit deleteSubreddit(subreddit, mContentResolver); // Reset last download date SharedPreferences.Editor settings = PreferenceManager.getDefaultSharedPreferences(mContext) .edit(); settings.remove(SettingsActivity.KEY_SYNC_LAST_MODIFIED + subreddit); settings.commit(); } } executor.shutdown(); executor.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS); } catch (URISyntaxException e) { Log.error("Emotes URL is malformed", e); synchronized (mSyncResult) { mSyncResult.stats.numParseExceptions++; if (mSyncResult.delayUntil < 60 * 60) mSyncResult.delayUntil = 60 * 60; } return; } catch (IOException e) { Log.error("Error reading from network: " + e.getMessage(), e); synchronized (mSyncResult) { mSyncResult.stats.numIoExceptions++; if (mSyncResult.delayUntil < 30 * 60) mSyncResult.delayUntil = 30 * 60; } return; } catch (InterruptedException e) { synchronized (mSyncResult) { syncResult.moreRecordsToGet = true; } Log.info("Sync interrupted"); executor.shutdownNow(); try { executor.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS); } catch (InterruptedException e2) { } Thread.currentThread().interrupt(); } finally { Log.info("Deleted emotes: " + Long.toString(mSyncResult.stats.numDeletes)); Log.info("Added emotes: " + Long.toString(mSyncResult.stats.numInserts)); // Unregisters BroadcastReceiver at the end mContext.unregisterReceiver(receiver); mHttpClient.close(); } Log.info("EmoteDownload finished"); }
From source file:com.tealeaf.NativeShim.java
public NativeShim(TextManager textManager, TextureLoader textureLoader, SoundQueue soundQueue, LocalStorage localStorage, ContactList contactList, LocationManager locationManager, ResourceManager resourceManager, TeaLeaf context) { this.textManager = textManager; this.textureLoader = textureLoader; new Thread(this.textureLoader).start(); this.soundQueue = soundQueue; this.localStorage = localStorage; this.contactList = contactList; this.haptics = new Haptics(context); this.locationManager = locationManager; this.resourceManager = resourceManager; this.context = context; this.remoteLogger = context.getRemoteLogger(); this.connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); this.networkStateReceiver = new NetworkStateReceiver(this); this.onlineStatus = false; this.updateOnlineStatus(); this.statusBarHeight = 0; int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { this.statusBarHeight = context.getResources().getDimensionPixelSize(resourceId); logger.log("status bar height:", this.statusBarHeight); }/*from ww w.ja v a 2 s . co m*/ IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); context.registerReceiver(this.networkStateReceiver, filter); }