Java Code Examples for android.net.ConnectivityManager#CONNECTIVITY_ACTION
The following examples show how to use
android.net.ConnectivityManager#CONNECTIVITY_ACTION .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WifiAutoConnect.java From ShareBox with Apache License 2.0 | 6 votes |
public void startScan() { _wifiManager= (WifiManager) _context.getSystemService(Context.WIFI_SERVICE); _wifiReceiver=new WifiReceiver(_wifiManager,this); _wifiManager.disconnect(); if(!_wifiManager.isWifiEnabled()) _wifiManager.setWifiEnabled(true); IntentFilter filter=new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); // IntentFilter filter=new IntentFilter("wifi_scan_available"); // filter.addAction("wifi_scan_available"); filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); _context.registerReceiver(_wifiReceiver,filter); }
Example 2
Source File: BaseTvActivity.java From VCL-Android with Apache License 2.0 | 6 votes |
@Override protected void onResume() { super.onResume(); //Handle network connection state IntentFilter networkfilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); IntentFilter storageFilter = new IntentFilter(Intent.ACTION_MEDIA_MOUNTED); storageFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); storageFilter.addDataScheme("file"); registerReceiver(mExternalDevicesReceiver, networkfilter); registerReceiver(mExternalDevicesReceiver, storageFilter); }
Example 3
Source File: ScreenOnOffUpdateService.java From your-local-weather with GNU General Public License v3.0 | 6 votes |
private void startNetworkConnectivityReceiver() { try { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { appendLog(getBaseContext(), TAG, "Start connectivity receiver with handler"); networkConnectivityReceiver = new NetworkConnectivityReceiver(); IntentFilter filterNetworkConnectivity = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); getApplicationContext().registerReceiver(networkConnectivityReceiver, filterNetworkConnectivity); } else { appendLog(getBaseContext(), TAG, "Start connectivity receiver with callback"); ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); networkConnectionReceiver = new NetworkConnectionReceiver(this); connectivityManager.registerDefaultNetworkCallback(networkConnectionReceiver); } } catch (Exception e) { appendLog(getBaseContext(), TAG, e); } }
Example 4
Source File: ConnectionsManager.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
public void init(int version, int layer, int apiId, String deviceModel, String systemVersion, String appVersion, String langCode, String systemLangCode, String configPath, String logPath, int userId, boolean enablePushConnection) { native_init(currentAccount, version, layer, apiId, deviceModel, systemVersion, appVersion, langCode, systemLangCode, configPath, logPath, userId, enablePushConnection, isNetworkOnline(), getCurrentNetworkType()); checkConnection(); BroadcastReceiver networkStateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { checkConnection(); FileLoader.getInstance(currentAccount).onNetworkChanged(isConnectionSlow()); } }; IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); ApplicationLoader.applicationContext.registerReceiver(networkStateReceiver, filter); }
Example 5
Source File: WifiPeriodicReplicationReceiverTest.java From sync-android with Apache License 2.0 | 6 votes |
/** * Check that when {@link WifiPeriodicReplicationReceiver} receives * {@link ConnectivityManager#CONNECTIVITY_ACTION} and WiFi is not connected, * an {@link Intent} is sent out to stop the Service * {@link ReplicationService} associated with * {@link WifiPeriodicReplicationReceiver} containing the extra * {@link ReplicationService#EXTRA_COMMAND} with the value * {@link PeriodicReplicationService#COMMAND_STOP_REPLICATION}. */ public void testWifiDisconnected() { Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION); mMockContext.setMockConnectivityManager(ConnectivityManager.TYPE_WIFI, false); when(mMockPreferences.getBoolean(ReplicationService.class.getName() + ".wasOnWifi", false)).thenReturn(true); mMockPreferencesEditor = mock(SharedPreferences.Editor.class); when(mMockPreferences.edit()).thenReturn(mMockPreferencesEditor); mReceiver.onReceive(mMockContext, intent); verify(mMockPreferencesEditor, times(1)).putBoolean(ReplicationService.class.getName() + ".wasOnWifi", false); assertEquals(1, mMockContext.getIntentsReceived().size()); Intent receivedIntent = mMockContext.getIntentsReceived().get(0); assertEquals(ReplicationService.class.getName(), receivedIntent.getComponent().getClassName()); assertNull(receivedIntent.getAction()); assertEquals(PeriodicReplicationService.COMMAND_STOP_REPLICATION, receivedIntent.getIntExtra(ReplicationService.EXTRA_COMMAND, ReplicationService.COMMAND_NONE)); }
Example 6
Source File: GeoFence_Keyword_Activity.java From Android_Location_Demo with Apache License 2.0 | 5 votes |
void init() { if (mAMap == null) { mAMap = mMapView.getMap(); mAMap.getUiSettings().setRotateGesturesEnabled(false); mAMap.moveCamera(CameraUpdateFactory.zoomBy(6)); setUpMap(); } lyOption.setVisibility(View.GONE); btOption.setText(getString(R.string.showOption)); resetView(); resetView_keyword(); btAddFence.setOnClickListener(this); btOption.setOnClickListener(this); cbAlertIn.setOnCheckedChangeListener(this); cbAlertOut.setOnCheckedChangeListener(this); cbAldertStated.setOnCheckedChangeListener(this); IntentFilter fliter = new IntentFilter( ConnectivityManager.CONNECTIVITY_ACTION); fliter.addAction(GEOFENCE_BROADCAST_ACTION); registerReceiver(mGeoFenceReceiver, fliter); /** * 创建pendingIntent */ fenceClient.createPendingIntent(GEOFENCE_BROADCAST_ACTION); fenceClient.setGeoFenceListener(this); /** * 设置地理围栏的触发行为,默认为进入 */ fenceClient.setActivateAction(GeoFenceClient.GEOFENCE_IN); }
Example 7
Source File: Application.java From PresencePublisher with MIT License | 5 votes |
@SuppressWarnings("deprecation") private void initNetworkReceiver() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { SystemBroadcastReceiver receiver = new SystemBroadcastReceiver(); IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(receiver, filter); } }
Example 8
Source File: MobileMessagingConnectivityReceiverTest.java From mobile-messaging-sdk-android with Apache License 2.0 | 5 votes |
@Test public void test_should_not_perform_retry_sync_on_internet_not_connected() throws Exception { // Given Intent givenIntent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION); givenIntent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true); // When mobileMessagingConnectivityReceiver.onReceive(contextMock, givenIntent); // Then verify(mmcMock, never()).retrySyncOnNetworkAvailable(); }
Example 9
Source File: BaseActivity.java From GracefulMovies with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mActivity = this; MARGIN_TOP_DP = Util.getStatusBarHeight() + Util.dp2px(56); mReceiver = new NetworkStateChangedReceiver(); IntentFilter intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(mReceiver, intentFilter); mBinding = DataBindingUtil.setContentView(this, contentLayoutRes()); afterSetContentView(); }
Example 10
Source File: ConnectivitySlot.java From Easer with GNU General Public License v3.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { switch (intent.getAction()) { case ConnectivityManager.CONNECTIVITY_ACTION: checkConnectivity(); break; } }
Example 11
Source File: ConnectivityReceiver.java From triviums with MIT License | 5 votes |
@Override protected void onActive() { super.onActive(); IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); context.registerReceiver(networkReceiver, filter); }
Example 12
Source File: NettyService.java From Netty_Demo with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); receiver = new NetworkReceiver(); IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); LocalBroadcastManager.getInstance(this).registerReceiver(receiver, filter); }
Example 13
Source File: GeoFence_Round_Activity.java From Android_Location_Demo with Apache License 2.0 | 5 votes |
void init() { if (mAMap == null) { mAMap = mMapView.getMap(); mAMap.getUiSettings().setRotateGesturesEnabled(false); mAMap.moveCamera(CameraUpdateFactory.zoomBy(6)); setUpMap(); } btOption.setVisibility(View.VISIBLE); btOption.setText(getString(R.string.hideOption)); resetView_round(); btAddFence.setOnClickListener(this); btOption.setOnClickListener(this); cbAlertIn.setOnCheckedChangeListener(this); cbAlertOut.setOnCheckedChangeListener(this); cbAldertStated.setOnCheckedChangeListener(this); IntentFilter fliter = new IntentFilter( ConnectivityManager.CONNECTIVITY_ACTION); fliter.addAction(GEOFENCE_BROADCAST_ACTION); registerReceiver(mGeoFenceReceiver, fliter); /** * 创建pendingIntent */ fenceClient.createPendingIntent(GEOFENCE_BROADCAST_ACTION); fenceClient.setGeoFenceListener(this); /** * 设置地理围栏的触发行为,默认为进入 */ fenceClient.setActivateAction(GeoFenceClient.GEOFENCE_IN); }
Example 14
Source File: GeoFence_Polygon_Activity.java From Android_Location_Demo with Apache License 2.0 | 5 votes |
void init() { if (mAMap == null) { mAMap = mMapView.getMap(); mAMap.getUiSettings().setRotateGesturesEnabled(false); mAMap.moveCamera(CameraUpdateFactory.zoomBy(6)); setUpMap(); } resetView_polygon(); btAddFence.setOnClickListener(this); cbAlertIn.setOnCheckedChangeListener(this); cbAlertOut.setOnCheckedChangeListener(this); cbAldertStated.setOnCheckedChangeListener(this); IntentFilter fliter = new IntentFilter( ConnectivityManager.CONNECTIVITY_ACTION); fliter.addAction(GEOFENCE_BROADCAST_ACTION); registerReceiver(mGeoFenceReceiver, fliter); /** * 创建pendingIntent */ fenceClient.createPendingIntent(GEOFENCE_BROADCAST_ACTION); fenceClient.setGeoFenceListener(this); /** * 设置地理围栏的触发行为,默认为进入 */ fenceClient.setActivateAction(GeoFenceClient.GEOFENCE_IN); }
Example 15
Source File: GeoFence_Polygon_Activity.java From Android_Location_Demo with Apache License 2.0 | 5 votes |
void init() { if (mAMap == null) { mAMap = mMapView.getMap(); mAMap.getUiSettings().setRotateGesturesEnabled(false); mAMap.moveCamera(CameraUpdateFactory.zoomBy(6)); setUpMap(); } resetView_polygon(); btAddFence.setOnClickListener(this); cbAlertIn.setOnCheckedChangeListener(this); cbAlertOut.setOnCheckedChangeListener(this); cbAldertStated.setOnCheckedChangeListener(this); IntentFilter fliter = new IntentFilter( ConnectivityManager.CONNECTIVITY_ACTION); fliter.addAction(GEOFENCE_BROADCAST_ACTION); registerReceiver(mGeoFenceReceiver, fliter); /** * 创建pendingIntent */ fenceClient.createPendingIntent(GEOFENCE_BROADCAST_ACTION); fenceClient.setGeoFenceListener(this); /** * 设置地理围栏的触发行为,默认为进入 */ fenceClient.setActivateAction(GeoFenceClient.GEOFENCE_IN); }
Example 16
Source File: MmsRadio.java From Silence with GNU General Public License v3.0 | 5 votes |
public synchronized void connect() throws MmsRadioException { int status; try { final Method startUsingNetworkFeatureMethod = connectivityManager.getClass().getMethod("startUsingNetworkFeature", Integer.TYPE, String.class); status = (int)startUsingNetworkFeatureMethod.invoke(connectivityManager, ConnectivityManager.TYPE_MOBILE, FEATURE_ENABLE_MMS); } catch (NoSuchMethodException nsme) { throw new MmsRadioException(nsme); } catch (IllegalAccessException iae) { throw new MmsRadioException(iae); } catch (InvocationTargetException ite) { throw new MmsRadioException(ite); } Log.w(TAG, "startUsingNetworkFeature status: " + status); if (status == APN_ALREADY_ACTIVE) { wakeLock.acquire(); connectedCounter++; return; } else { wakeLock.acquire(); connectedCounter++; if (connectivityListener == null) { IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); connectivityListener = new ConnectivityListener(); context.registerReceiver(connectivityListener, filter); } Util.wait(this, 30000); if (!isConnected()) { Log.w(TAG, "Got back from connectivity wait, and not connected..."); disconnect(); throw new MmsRadioException("Unable to successfully enable MMS radio."); } } }
Example 17
Source File: NetworkBrowserFragment.java From VCL-Android with Apache License 2.0 | 5 votes |
public void onStart(){ super.onStart(); //Handle network connection state IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); getActivity().registerReceiver(networkReceiver, filter); }
Example 18
Source File: CloudManager.java From thunderboard-android with Apache License 2.0 | 4 votes |
private void registerWifiUpdateReceiver() { IntentFilter connectionFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); context.registerReceiver(wifiUpdateReceiver, connectionFilter); }
Example 19
Source File: DownloadController.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public DownloadController(int instance) { currentAccount = instance; SharedPreferences preferences = MessagesController.getMainSettings(currentAccount); for (int a = 0; a < 4; a++) { String key = "mobileDataDownloadMask" + (a == 0 ? "" : a); if (a == 0 || preferences.contains(key)) { mobileDataDownloadMask[a] = preferences.getInt(key, AUTODOWNLOAD_MASK_PHOTO | AUTODOWNLOAD_MASK_AUDIO | AUTODOWNLOAD_MASK_MUSIC | AUTODOWNLOAD_MASK_GIF | AUTODOWNLOAD_MASK_VIDEOMESSAGE); wifiDownloadMask[a] = preferences.getInt("wifiDownloadMask" + (a == 0 ? "" : a), AUTODOWNLOAD_MASK_PHOTO | AUTODOWNLOAD_MASK_AUDIO | AUTODOWNLOAD_MASK_MUSIC | AUTODOWNLOAD_MASK_GIF | AUTODOWNLOAD_MASK_VIDEOMESSAGE); roamingDownloadMask[a] = preferences.getInt("roamingDownloadMask" + (a == 0 ? "" : a), 0); } else { mobileDataDownloadMask[a] = mobileDataDownloadMask[0]; wifiDownloadMask[a] = wifiDownloadMask[0]; roamingDownloadMask[a] = roamingDownloadMask[0]; } } for (int a = 0; a < 7; a++) { int sdefault; if (a == 1) { sdefault = 2 * 1024 * 1024; } else if (a == 6) { sdefault = 5 * 1024 * 1024; } else { sdefault = 10 * 1024 * 1024; } mobileMaxFileSize[a] = preferences.getInt("mobileMaxDownloadSize" + a, sdefault); wifiMaxFileSize[a] = preferences.getInt("wifiMaxDownloadSize" + a, sdefault); roamingMaxFileSize[a] = preferences.getInt("roamingMaxDownloadSize" + a, sdefault); } globalAutodownloadEnabled = preferences.getBoolean("globalAutodownloadEnabled", false); AndroidUtilities.runOnUIThread(() -> { NotificationCenter.getInstance(currentAccount).addObserver(DownloadController.this, NotificationCenter.FileDidFailedLoad); NotificationCenter.getInstance(currentAccount).addObserver(DownloadController.this, NotificationCenter.FileDidLoaded); NotificationCenter.getInstance(currentAccount).addObserver(DownloadController.this, NotificationCenter.FileLoadProgressChanged); NotificationCenter.getInstance(currentAccount).addObserver(DownloadController.this, NotificationCenter.FileUploadProgressChanged); NotificationCenter.getInstance(currentAccount).addObserver(DownloadController.this, NotificationCenter.httpFileDidLoaded); NotificationCenter.getInstance(currentAccount).addObserver(DownloadController.this, NotificationCenter.httpFileDidFailedLoad); }); BroadcastReceiver networkStateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { checkAutodownloadSettings(); } }; IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); ApplicationLoader.applicationContext.registerReceiver(networkStateReceiver, filter); if (UserConfig.getInstance(currentAccount).isClientActivated()) { checkAutodownloadSettings(); } }
Example 20
Source File: ConnectivityWire.java From tinybus with Apache License 2.0 | 4 votes |
public ConnectivityWire(Class<? extends ConnectionStateEvent> producedEventClass) { mpProducedEventClass = producedEventClass; mFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); }