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.aegiswallet.services.PeerBlockchainService.java
@Override public void onCreate() { super.onCreate(); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); application = (PayBitsApplication) getApplication(); prefs = PreferenceManager.getDefaultSharedPreferences(this); final Wallet wallet = application.getWallet(); blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.BLOCKCHAIN_FILENAME); final boolean blockChainFileExists = blockChainFile.exists(); if (!blockChainFileExists) { wallet.clearTransactions(0);/* w ww . j ava 2 s. c o m*/ wallet.setLastBlockSeenHeight(-1); wallet.setLastBlockSeenHash(null); } try { blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile); blockStore.getChainHead(); // detect corruptions as early as possible long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime(); if (earliestKeyCreationTime == 0) earliestKeyCreationTime = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7); if (!blockChainFileExists && earliestKeyCreationTime > 0) { Log.d(TAG, "creating blockchain from checkpoint. attmpting to at least..."); try { final InputStream checkpointsInputStream = getAssets().open(Constants.CHECKPOINTS_FILENAME); CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsInputStream, blockStore, earliestKeyCreationTime); } catch (final IOException x) { Log.e(TAG, "problem reading checkpoint file..." + x.getMessage()); } } } catch (final BlockStoreException x) { blockChainFile.delete(); final String msg = "blockstore cannot be created"; throw new Error(msg, x); } try { blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore); } catch (final BlockStoreException x) { throw new Error("blockchain cannot be created", x); } bestChainHeightEver = prefs.getInt(Constants.PREFS_KEY_BEST_CHAIN_HEIGHT_EVER, 0); peerConnectivityListener = new PeerConnectivityListener(); sendBroadcastPeerState(0); final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW); intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK); registerReceiver(connectivityReceiver, intentFilter); registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); maybeRotateKeys(); tagPrefs = application.getSharedPreferences(getString(R.string.tag_pref_filename), Context.MODE_PRIVATE); }
From source file:com.ubergeek42.WeechatAndroid.service.RelayServiceBackbone.java
@Override public void onCreate() { if (DEBUG)/*from w ww . j a v a2 s . c o m*/ logger.debug("onCreate()"); super.onCreate(); prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); prefs.registerOnSharedPreferenceChangeListener(this); notificationManger = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // prepare handler that will run on a separate thread HandlerThread handler_thread = new HandlerThread("doge"); handler_thread.start(); thandler = new Handler(handler_thread.getLooper()); startForeground(NOTIFICATION_ID, buildNotification(null, "Tap to connect", null)); disconnected = false; already_had_intent = false; network_unavailable = false; // Prepare for dealing with SSL certs certmanager = new SSLHandler(new File(getDir("sslDir", Context.MODE_PRIVATE), "keystore.jks")); registerReceiver(connectivityActionReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); }
From source file:ro.ui.pttdroid.Client_Main.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.client_main); userName = (TextView) findViewById(R.id.userName_client); title = (TextView) findViewById(R.id.title); content = (TextView) findViewById(R.id.content); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); getActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.bar)); //? //???// w ww .j ava2 s .com getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //ml.release(); /*ImageButton ready_image_guide; ready_image_guide=(ImageButton)findViewById(R.id.ready_image_guide); ready_image_guide.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub change_to_client_online_fragment(); } }); */ //getActionBar().setBackgroundDrawable(null); System.out.println("start main!!!!!!!!!!"); Intent intent = this.getIntent(); //??? if_Global_local = intent.getIntExtra("if_Global_local", -2); System.out.println("if_Global_local" + if_Global_local); try { ParseHelper.initParse(this); EventBus.getDefault().postSticky("Parse init success!"); } catch (Exception e) { EventBus.getDefault().postSticky("Failed to int parse!"); } /*ImageButton listen_guide = (ImageButton) findViewById(R.id.listen_guide); listen_guide .setOnClickListener(new View.OnClickListener() { public void onClick(View v) { }});*/ init(); /*change_to_client_online_fragment(); playerIntent = new Intent(this, Client_Player.class); startService(playerIntent); */ if (if_Global_local == 1) { System.out.println("local"); if (if_clientL_offline_mode) { if_clientL_offline_mode = false; change_to_client_online_fragment(); playerIntent = new Intent(this, Client_Player.class); startService(playerIntent); } } if (if_Global_local == 0) { System.out.println("global"); if (if_clientL_offline_mode) { if_loading_final = true; if_clientL_offline_mode = false; microphoneSwitcher.hide(); change_to_client_Global_online_fragment(); } invalidateOptionsMenu(); } //microphoneSwitcher.hide(); intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); channel = manager.initialize(this, getMainLooper(), null); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); EventBus.getDefault().register(this); // test_connect(); }
From source file:com.ephemeraldreams.gallyshuttle.ui.ScheduleActivity.java
/** * Register a {@link #networkStateBroadCastReceiver}, which monitor for Internet connection * re-establishment./*from ww w .j a v a2 s. co m*/ */ private void registerNetworkBroadcastReceiver() { networkStateBroadCastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // Internet connection has been re-established. unregisterNetworkBroadcastReceiver(); } }; registerReceiver(networkStateBroadCastReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); isNetworkStateBroadcastReceiverRegistered = true; }
From source file:com.mappn.gfan.ui.HomeTabActivity.java
private void registerReceivers() { IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(mNetworkReceiver, filter); IntentFilter intentClickFilter = new IntentFilter(Constants.BROADCAST_CLICK_INTENT); registerReceiver(mIntentClickReceiver, intentClickFilter); IntentFilter appFilter = new IntentFilter(); appFilter.addAction(Intent.ACTION_PACKAGE_ADDED); appFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); appFilter.addAction(Intent.ACTION_PACKAGE_CHANGED); appFilter.addDataScheme("package"); registerReceiver(mInstallReceiver, appFilter); IntentFilter updatefilter = new IntentFilter(); updatefilter.addAction(Constants.BROADCAST_FORCE_EXIT); updatefilter.addAction(Constants.BROADCAST_REMIND_LATTER); updatefilter.addAction(Constants.BROADCAST_DOWNLOAD_OPT); updatefilter.addAction(Constants.BROADCAST_DOWNLOAD); registerReceiver(mUpdateReceiver, updatefilter); }
From source file:com.sonaive.v2ex.ui.BaseActivity.java
@Override protected void onStart() { super.onStart(); IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); mReceiver = new NetworkChangeReceiver(); registerReceiver(mReceiver, filter); startLoginProcess();// w w w .j a v a2s.c o m EventBus.getDefault().registerSticky(this); }
From source file:nl.dobots.presence.PresenceDetectionApp.java
@Override public void onCreate() { super.onCreate(); instance = this; // load settings from persistent storage _settings = Settings.getInstance();//from ww w .j av a 2 s . c o m _settings.readPersistentStorage(getApplicationContext()); _settings.readPersistentLocations(getApplicationContext()); // get localization algo _localization = new SimpleLocalization(_settings.getLocationsList(), _settings.getDetectionDistance()); // get ask wrapper (wraps login and presence functions) _ask = AskWrapper.getInstance(); _notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // watchdog handler checks for non-presence and handles manual override HandlerThread watchdogThread = new HandlerThread("Watchdog"); watchdogThread.start(); _watchdogHandler = new Handler(watchdogThread.getLooper()); _watchdogHandler.postDelayed(_watchdogRunner, Config.WATCHDOG_INTERVAL); // network handler used for network operations (login, updatePresence, etc.) HandlerThread networkThread = new HandlerThread("NetworkHandler"); networkThread.start(); _networkHandler = new Handler(networkThread.getLooper()); // filter for connectivity broadcasts IntentFilter filter = new IntentFilter(); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(_receiver, filter); // Intent startServiceIntent = new Intent(this, BleScanService.class); // this.startService(startServiceIntent); Intent intent = new Intent(this, BleScanService.class); bindService(intent, _connection, Context.BIND_AUTO_CREATE); // set expiration time for RSSI measurements. keeps measurements of 5 scan intervals // before throwing them out. i.e. averages over all measurements received in the last 5 // scan intervals BleDevice.setExpirationTime(5 * (Config.LOW_SCAN_PAUSE + Config.LOW_SCAN_INTERVAL)); }
From source file:org.compose.mobilesdk.android.COMPOSESubService.java
/** * Attempts connect to the Mqtt Broker//from ww w . j a v a 2s . c o m * and listen for Connectivity changes * via ConnectivityManager.CONNECTVITIY_ACTION BroadcastReceiver */ private synchronized void start() { if (mStarted) { Log.i(DEBUG_TAG, "Attempt to start while already started"); return; } if (hasScheduledKeepAlives()) { stopKeepAlives(); } connect(); registerReceiver(mConnectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); }
From source file:com.mobicage.rpc.http.HttpCommunicator.java
public HttpCommunicator(final MainService mainService, final Context context, final DatabaseManager databaseManager, final Credentials credentials, final ConfigurationProvider cfgProvider, final SafeRunnable onStartStashingHandler, final SafeRunnable onStopStashingHandler, final SDCardLogger sdcardLogger, final boolean wifiOnlySettingEnabled) { T.UI();/*from w ww .j a va2s . c om*/ mMainService = mainService; mCfgProvider = cfgProvider; mFinishedLock = new Object(); mStateMachineLock = new Object(); mStartStashingHandler = onStartStashingHandler; mStopStashingHandler = onStopStashingHandler; mWifiOnlyEnabled = wifiOnlySettingEnabled; mSDCardLogger = sdcardLogger; mAlarmManager = (AlarmManager) mMainService.getSystemService(Context.ALARM_SERVICE); // Create network thread for actual network communication mNetworkWorkerThread = new HandlerThread("rogerthat_net_worker"); mNetworkWorkerThread.start(); final Looper looper = mNetworkWorkerThread.getLooper(); mNetworkHandler = new Handler(looper); mNetworkHandler.post(new SafeRunnable() { @Override protected void safeRun() throws Exception { debugLog("HTTP network thread id is " + android.os.Process.myTid()); } }); final CountDownLatch latch = new CountDownLatch(1); mMainService.postAtFrontOfBIZZHandler(new SafeRunnable() { @Override public void safeRun() { T.BIZZ(); // For simplicity, I want to construct backlog on HTTP thread // This way backlog is 100% on HTTP thread mBacklog = new HttpBacklog(context, databaseManager); latch.countDown(); } }); try { latch.await(); } catch (InterruptedException e) { bugLog(e); } mBase64Username = Base64.encodeBytes(credentials.getUsername().getBytes(), Base64.DONT_BREAK_LINES); mBase64Password = Base64.encodeBytes(credentials.getPassword().getBytes(), Base64.DONT_BREAK_LINES); mMainService.addHighPriorityIntent(HttpCommunicator.INTENT_HTTP_START_OUTGOING_CALLS); if (CloudConstants.USE_GCM_KICK_CHANNEL) { final IntentFilter filter = new IntentFilter(); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); filter.addAction(INTENT_SHOULD_RETRY_COMMUNICATION); mMainService.registerReceiver(mBroadcastReceiver, filter); } }
From source file:com.CPTeam.VselCalc.AutoUpdateApk.java
private void setupVariables(Context ctx) { context = ctx;/*from w w w . j av a 2s . c o m*/ packageName = context.getPackageName(); preferences = context.getSharedPreferences(packageName + "_" + TAG, Context.MODE_PRIVATE); device_id = crc32(Secure.getString(context.getContentResolver(), Secure.ANDROID_ID)); last_update = preferences.getLong("last_update", 0); NOTIFICATION_ID += crc32(packageName); ApplicationInfo appinfo = context.getApplicationInfo(); if (appinfo.icon != 0) { appIcon = appinfo.icon; } else { Log_w(TAG, "unable to find application icon"); } if (appinfo.labelRes != 0) { appName = context.getString(appinfo.labelRes); } else { Log_w(TAG, "unable to find application label"); } if (new File(appinfo.sourceDir).lastModified() > preferences.getLong(MD5_TIME, 0)) { preferences.edit().putString(MD5_KEY, MD5Hex(appinfo.sourceDir)).commit(); preferences.edit().putLong(MD5_TIME, System.currentTimeMillis()).commit(); String update_file = preferences.getString(UPDATE_FILE, ""); if (update_file.length() > 0) { if (new File(context.getFilesDir().getAbsolutePath() + "/" + update_file).delete()) { preferences.edit().remove(UPDATE_FILE).remove(SILENT_FAILED).commit(); } } } raise_notification(); if (haveInternetPermissions()) { context.registerReceiver(connectivity_receiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); } }