private void registerReceivers() { LocalBroadcastManager localBroadcastMgr = LocalBroadcastManager.getInstance(mCtx); localBroadcastMgr.registerReceiver( mArdiscoveryServicesDevicesListUpdatedReceiver, new IntentFilter( ARDiscoveryService.kARDiscoveryServiceNotificationServicesDevicesListUpdated)); }
public void performViewSetup() { final WatchViewStub stub = (WatchViewStub) layoutView.findViewById(R.id.watch_view_stub); IntentFilter messageFilter = new IntentFilter(Intent.ACTION_SEND); messageReceiver = new MessageReceiver(); localBroadcastManager = LocalBroadcastManager.getInstance(this); localBroadcastManager.registerReceiver(messageReceiver, messageFilter); stub.setOnLayoutInflatedListener( new WatchViewStub.OnLayoutInflatedListener() { @Override public void onLayoutInflated(WatchViewStub stub) { mTime = (TextView) stub.findViewById(R.id.watch_time); mSgv = (TextView) stub.findViewById(R.id.sgv); mDirection = (TextView) stub.findViewById(R.id.direction); mTimestamp = (TextView) stub.findViewById(R.id.timestamp); mUploaderBattery = (TextView) stub.findViewById(R.id.uploader_battery); mDelta = (TextView) stub.findViewById(R.id.delta); mRelativeLayout = (RelativeLayout) stub.findViewById(R.id.main_layout); mLinearLayout = (LinearLayout) stub.findViewById(R.id.secondary_layout); chart = (LineChartView) stub.findViewById(R.id.chart); layoutSet = true; mRelativeLayout.measure(specW, specH); mRelativeLayout.layout( 0, 0, mRelativeLayout.getMeasuredWidth(), mRelativeLayout.getMeasuredHeight()); } }); ListenerService.requestData(this); wakeLock.acquire(50); }
private void registerReceiver() { mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); IntentFilter filter = new IntentFilter(); filter.addAction(Actions.SHOW_ALERT_SEND_SMS_FAILED_OUT_OF_FREE_SMS); filter.addAction(Actions.SHOW_ALERT_SEND_SMS_FAILED_WRONG_NUMBER); mLocalBroadcastManager.registerReceiver(mBroadcastReceiver, filter); }
@Override public boolean onOptionsItemSelected(MenuItem mItem) { switch (mItem.getItemId()) { case R.id.action_settings: startActivity(new Intent(this, SettingsActivity.class)); return true; case R.id.action_help: startActivity(new Intent(this, HelpActivity.class)); return true; case R.id.action_bluetooth_settings: startActivity(new Intent().setAction(Settings.ACTION_BLUETOOTH_SETTINGS)); return true; case R.id.action_bluetooth: startActivityForResult( new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), REQUEST_ENABLE_BT); return true; case R.id.action_save: LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(RecordFragment.SAVE_DATA)); return true; case R.id.action_clear_data: LocalBroadcastManager.getInstance(this) .sendBroadcast(new Intent(RecordFragment.CLEAR_DATA)); return true; case R.id.action_rescan: fConnect.scanForDevices(true); return true; default: return super.onOptionsItemSelected(mItem); } }
@Override public void onResume() { super.onResume(); resetNetworkInfo(); setRepoSwitchChecked(FDroidApp.isLocalRepoServiceRunnig()); LocalBroadcastManager.getInstance(this) .registerReceiver(onWifiChange, new IntentFilter(WifiStateChangeService.BROADCAST)); LocalBroadcastManager.getInstance(this) .registerReceiver(onLocalRepoChange, new IntentFilter(LocalRepoService.STATE)); // if no local repo exists, create one with only FDroid in it if (!LocalRepoManager.get(this).xmlIndex.exists()) new UpdateAsyncTask( this, new String[] { getPackageName(), }) .execute(); // start repo by default FDroidApp.startLocalRepoService(LocalRepoActivity.this); // reset the timer if viewing this Activity again if (stopTimer != null) stopTimer.cancel(); // automatically turn off after 15 minutes stopTimer = new Timer(); stopTimer.schedule( new TimerTask() { @Override public void run() { FDroidApp.stopLocalRepoService(LocalRepoActivity.this); } }, 900000); // 15 minutes }
@Override protected void onStart() { super.onStart(); // Ensure the progress bar is hidden when starting progressBar.setVisibility(View.GONE); // Monitor the schedule download LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); lbm.registerReceiver( scheduleDownloadProgressReceiver, new IntentFilter(Api.ACTION_DOWNLOAD_SCHEDULE_PROGRESS)); lbm.registerReceiver( scheduleDownloadResultReceiver, new IntentFilter(Api.ACTION_DOWNLOAD_SCHEDULE_RESULT)); // Download reminder long now = System.currentTimeMillis(); long time = DatabaseManager.getInstance().getLastUpdateTime(); if ((time == -1L) || (time < (now - DATABASE_VALIDITY_DURATION))) { SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); time = prefs.getLong(PREF_LAST_DOWNLOAD_REMINDER_TIME, -1L); if ((time == -1L) || (time < (now - DOWNLOAD_REMINDER_SNOOZE_DURATION))) { SharedPreferencesCompat.EditorCompat.getInstance() .apply(prefs.edit().putLong(PREF_LAST_DOWNLOAD_REMINDER_TIME, now)); FragmentManager fm = getSupportFragmentManager(); if (fm.findFragmentByTag("download_reminder") == null) { new DownloadScheduleReminderDialogFragment().show(fm, "download_reminder"); } } } }
public int processEventChars(boolean var1, short var2, short var3) throws InterruptedException { long var6 = 0L; boolean var8 = false; boolean var9 = false; var6 = 0L; q var10 = new q(); var10.a = this.ftDevice.i.a; Intent intent; if (var1 && (var10.a & 1L) != 0L && (this.ftDevice.a ^ 1L) == 1L) { this.ftDevice.a |= 1L; intent = new Intent("FT_EVENT_RXCHAR"); intent.putExtra("message", "FT_EVENT_RXCHAR"); LocalBroadcastManager.getInstance(this.ftDevice.context).sendBroadcast(intent); } if (var2 != 0 && (var10.a & 2L) != 0L && (this.ftDevice.a ^ 2L) == 2L) { this.ftDevice.a |= 2L; intent = new Intent("FT_EVENT_MODEM_STATUS"); intent.putExtra("message", "FT_EVENT_MODEM_STATUS"); LocalBroadcastManager.getInstance(this.ftDevice.context).sendBroadcast(intent); } if (var3 != 0 && (var10.a & 4L) != 0L && (this.ftDevice.a ^ 4L) == 4L) { this.ftDevice.a |= 4L; intent = new Intent("FT_EVENT_LINE_STATUS"); intent.putExtra("message", "FT_EVENT_LINE_STATUS"); LocalBroadcastManager.getInstance(this.ftDevice.context).sendBroadcast(intent); } return 0; }
@Override public void onResume() { // onResume is called after onActivityCreated, when the fragment is loaded 100% Log.d(TAG, "onResume"); super.onResume(); if (map == null) { Log.w(TAG, "Map null. creating it."); setUpMap(); setupAddPlacesOverlay(); } else { Log.d(TAG, "Map already exists. Nothing to do."); } LocalBroadcastManager.getInstance(context) .registerReceiver(mMessageReceiver, new IntentFilter("LOCATION-UPDATE")); LocalBroadcastManager.getInstance(context) .registerReceiver(placesUpdateReceiver, new IntentFilter("PLACES-UPDATE")); checkLocationServiceStatus(); new UpdateMap().execute(MapUserTypes.All); cancelAsyncTasks = false; if (MainApplication.places != null) { updatePlaces(); } AnalyticsUtils.screenHit(getString(R.string.analytics_screen_map)); }
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_ON) { Intent refreshIntent = new Intent(ControlCenter.ACTION_REFRESH_DEVICELIST); LocalBroadcastManager.getInstance(context).sendBroadcast(refreshIntent); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); if (!sharedPrefs.getBoolean("general_autoconnectonbluetooth", false)) { return; } GBApplication.deviceService().connect(); } else if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_OFF) { GBApplication.deviceService().quit(); Intent quitIntent = new Intent(GBApplication.ACTION_QUIT); LocalBroadcastManager.getInstance(context).sendBroadcast(quitIntent); } } }
@Override public void onDismiss(final DialogInterface dialog) { final LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(getActivity()); localBroadcastManager.sendBroadcast(new Intent(RESET_CLOSE_ACTION)); super.onDismiss(dialog); }
@Override public void onPause() { super.onPause(); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getActivity()); lbm.unregisterReceiver(mReceiver); }
/** * Static helper method to send broadcasts to the BaseActivity and enable or disable buttons * * @param context * @param buttonsDisabled to enable buttons apply and revert */ public static void setButtonsDisabledBroadcast(Context context, boolean buttonsDisabled) { LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context); Intent intent = new Intent(ACTION_BUTTONS); intent.putExtra(EXTRA_BUTTONS_DISABLED, buttonsDisabled); localBroadcastManager.sendBroadcast(intent); }
@Override public void onResume() { super.onResume(); LocalBroadcastManager.getInstance(getActivity()) .registerReceiver(mChatButtonReceiver, mChatButtonIntentFilter); LocalBroadcastManager.getInstance(getActivity()) .registerReceiver(mChatLaunchReceiver, mChatLaunchIntentFilter); }
@Override public void onResume() { super.onResume(); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getActivity()); lbm.registerReceiver(mReceiver, new IntentFilter(StatUtils.STATS_SUMMARY_UPDATED)); refreshSummary(); }
/** * Unregisters a broadcast receiver with the parent tutorial's {@link LocalBroadcastManager}. * * @param receiver The broadcast receiver to unregister. */ protected void unregisterReceiver(BroadcastReceiver receiver) { final LocalBroadcastManager manager = LocalBroadcastManager.getInstance(mParentTutorial); if (manager == null) { return; } manager.unregisterReceiver(receiver); }
@Override public void onDestroy() { LocalBroadcastManager.getInstance(this).unregisterReceiver(manualActivationReceiver); LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("service-stopped")); isRunning = false; stopForeground(true); ui.stop(); super.onDestroy(); }
@Override protected void loadData() { LocalBroadcastManager.getInstance(this) .registerReceiver( locationChangeReceiver, new IntentFilter("com.kplus.car.location.changed")); LocalBroadcastManager.getInstance(this) .registerReceiver(vehicleSyncReceiver, new IntentFilter(KplusConstants.ACTION_GET_SYN)); setCityAndFetchServices(); }
private void registerReceivers() { LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); lbm.registerReceiver( scheduleRefreshedReceiver, new IntentFilter(DatabaseManager.ACTION_SCHEDULE_REFRESHED)); IntentFilter filter = new IntentFilter(); filter.addAction(DatabaseManager.ACTION_ADD_BOOKMARK); filter.addAction(DatabaseManager.ACTION_REMOVE_BOOKMARKS); lbm.registerReceiver(bookmarksReceiver, filter); }
@Override protected void onHandleIntent(Intent intent) { // Only for test, send a broadcast intent Intent mIntent = new Intent(); mIntent.setAction(Constants.INTENT_ACTION); mIntent.putExtra(Constants.INTENT_EXTRA, "Additional info"); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); lbm.sendBroadcast(mIntent); }
/** * Static helper method to send broadcasts to the BaseActivity and update status in frontend * * @param context * @param title * @param text * @param iconStatus Select UPDATE_AVAILABLE, ENABLED, DISABLED, DOWNLOAD_FAIL, or CHECKING from * StatusCodes */ public static void setStatusBroadcast( Context context, String title, String text, int iconStatus) { LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context); Intent intent = new Intent(ACTION_UPDATE_STATUS); intent.putExtra(EXTRA_UPDATE_STATUS_ICON, iconStatus); intent.putExtra(EXTRA_UPDATE_STATUS_TITLE, title); intent.putExtra(EXTRA_UPDATE_STATUS_TEXT, text); localBroadcastManager.sendBroadcast(intent); }
public BookmarkStatusLoader(Context context, FossasiaEvent event) { super(context); this.event = event; LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); lbm.registerReceiver( addBookmarkReceiver, new IntentFilter(DatabaseManager.ACTION_ADD_BOOKMARK)); lbm.registerReceiver( removeBookmarksReceiver, new IntentFilter(DatabaseManager.ACTION_REMOVE_BOOKMARKS)); }
public void bindBroadCastReceivers(boolean bind) { if (bind) { /* Auf Meldungen horchen, die über den Status der Verbindung zum Broker informieren */ LocalBroadcastManager.getInstance(this) .registerReceiver( mServiceStatusReceiver, new IntentFilter(Config.SERVICE_CON_STATUS_FILTER)); } else { LocalBroadcastManager.getInstance(this).unregisterReceiver(mServiceStatusReceiver); } }
/** 获取消息 若有聊天窗口,则通过广播发送 否则保存到数据库 */ private void fetchMessages() { try { List<Message> messages = MessageAPI.queryMessages(); if (messages == null) return; MessageDB messageDB = MessageDB.getInstance(this); for (Message message : messages) { FriendsDB friendsDB = FriendsDB.getInstance(this); FriendProfile friendProfile = friendsDB.findFriend(message.getUsername()); Session session = new Session(); session.setUsername(friendProfile.getUsername()); if (message.getType() == Message.VALUE_LEFT_TEXT) { session.setLastWord(message.getText()); } else if (message.getType() == Message.VALUE_LEFT_IMAGE) { session.setLastWord("(图片)"); } LogUtil.i(TAG, "收到!!!!!!!!"); session.setTime(System.currentTimeMillis()); SessionDB sessionDB = SessionDB.getInstance(this); sessionDB.saveSession(session); // 保存会话 messageDB.saveMessage(message, "UNREAD"); // 保存消息,未读 // 当前是主Activity,更新session if (MyChatUtility.getRunningActivityName(this) .equals("com.gl.mychatclient.activities.MainActivity")) { Intent intent = new Intent("com.gl.mychatclient.BROADCAST_UPDATE_SESSION"); localBroadcastManager.sendBroadcast(intent); } if (MyChatUtility.getRunningActivityName(this) .equals("com.gl.mychatclient.activities.ChatActivity")) { // 当前是聊天Activity Intent intent = new Intent("com.gl.mychatclient.BROADCAST_RECEIVE_MESSAGE"); localBroadcastManager.sendBroadcast(intent); } else { // 没开启聊天窗口,则发送通知 if (message.getType() == Message.VALUE_LEFT_TEXT) { Intent intent = new Intent(this, ChatActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); if (friendProfile.getFriendNote() != null) intent.putExtra("title", friendProfile.getFriendNote()); else intent.putExtra("title", friendProfile.getNickname()); intent.putExtra("username", message.getUsername()); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); int sessionId = sessionDB.findSessionId(friendProfile.getUsername()); if (friendProfile.getFriendNote() != null) { MyChatUtility.sendNotification( this, sessionId, friendProfile.getFriendNote(), message.getText(), pendingIntent); } else { MyChatUtility.sendNotification( this, sessionId, friendProfile.getNickname(), message.getText(), pendingIntent); } } } } } catch (Exception e) { e.printStackTrace(); } }
@Override protected void onReset() { super.onReset(); onStopLoading(); isBookmarked = null; LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); lbm.unregisterReceiver(addBookmarkReceiver); lbm.unregisterReceiver(removeBookmarksReceiver); }
private void initBroadcastReceivers() { LocalBroadcastManager.getInstance(App.getAppContext()) .unregisterReceiver(cardAddedBroadcastReceiver); LocalBroadcastManager.getInstance(App.getAppContext()) .registerReceiver(cardAddedBroadcastReceiver, new IntentFilter(ADDED_CARD_INTENT)); LocalBroadcastManager.getInstance(App.getAppContext()) .unregisterReceiver(searchCardBroadcastReceiver); LocalBroadcastManager.getInstance(App.getAppContext()) .registerReceiver(searchCardBroadcastReceiver, new IntentFilter(SEARCH_CARD_INTENT)); }
private void broadcastChange() { Zup.getInstance().updateSyncAction(this); Intent intent = new Intent(SyncAction.ACTION_SYNC_CHANGED); intent.putExtra("sync_action", this); if (ZupApplication.getContext() == null) return; LocalBroadcastManager manager = LocalBroadcastManager.getInstance(ZupApplication.getContext()); manager.sendBroadcast(intent); }
@Override protected void onStop() { if ((searchMenuItem != null) && (MenuItemCompat.isActionViewExpanded(searchMenuItem))) { MenuItemCompat.collapseActionView(searchMenuItem); } LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); lbm.unregisterReceiver(scheduleDownloadProgressReceiver); lbm.unregisterReceiver(scheduleDownloadResultReceiver); super.onStop(); }
/** * Broadcasts a new intent with the result of the login and finishes this activity. * * @param token the received login token, or null if an error happened. */ private void sendBackResult(String token) { Intent result = new Intent(ACTION_LOGIN_RESULT); if (token == null || token.isEmpty()) { result.putExtra(EXTRA_SUCCESS, false); } else { result.putExtra(EXTRA_SUCCESS, true); result.putExtra(EXTRA_TOKEN, token); } LocalBroadcastManager manager = LocalBroadcastManager.getInstance(SimpleAuthActivity.this); manager.sendBroadcast(result); finish(); }
@Override public void run() { if (actionTerminated) return; stopTimer(); if (numberOfProcessedMessages < numberMessagesReceived) { startTimer(10000); Log.d( TAG, "Timer timed out by not all messages were processed. So restarting time out timer"); return; } for (Participant p : poll.getParticipants().values()) { if (AbstractAction.this instanceof SetupRoundAction) { if (!messagesReceived.containsKey(p.getUniqueId())) { // notify exclusion LocalBroadcastManager.getInstance(AndroidApplication.getInstance()) .sendBroadcast( new Intent(BroadcastIntentTypes.proofVerificationFailed) .putExtra("type", 2) .putExtra("participant", p.getIdentification())); poll.getCompletelyExcludedParticipants().put(p.getUniqueId(), p); } Log.w( TAG, "Participant " + p.getIdentification() + " (" + p.getUniqueId() + ") did not responde before timed out for submitting the setup value, so he was completely excluded (also from recovery)."); } else if (!messagesReceived.containsKey(p.getUniqueId()) && !poll.getCompletelyExcludedParticipants().containsKey(p.getUniqueId())) { poll.getExcludedParticipants().put(p.getUniqueId(), p); // notify exclusion LocalBroadcastManager.getInstance(AndroidApplication.getInstance()) .sendBroadcast( new Intent(BroadcastIntentTypes.proofVerificationFailed) .putExtra("type", 2) .putExtra("participant", p.getIdentification())); Log.w( TAG, "Excluding participant " + p.getIdentification() + " (" + p.getUniqueId() + ") because not sending his message."); } } goToNextState(); }
protected void transmitData(Context context, Bundle data) { if (context != null) { UUID uuid = UUID.randomUUID(); data.putString(Probe.PROBE_GUID, uuid.toString()); LocalBroadcastManager localManager = LocalBroadcastManager.getInstance(context); Intent intent = new Intent(edu.northwestern.cbits.purple_robot_manager.probes.Probe.PROBE_READING); intent.putExtras(data); localManager.sendBroadcast(intent); } }