androidx.localbroadcastmanager.content.LocalBroadcastManager Java Examples
The following examples show how to use
androidx.localbroadcastmanager.content.LocalBroadcastManager.
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: ProfileListFragment.java From SecondScreen with Apache License 2.0 | 6 votes |
@Override public void onStart() { super.onStart(); LocalBroadcastManager.getInstance(getActivity()).registerReceiver(receiver, filter); // Floating action button FloatingActionButton floatingActionButton = getActivity().findViewById(R.id.button_floating_action); floatingActionButton.setImageResource(R.drawable.ic_action_new); if(getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large")) floatingActionButton.hide(); if(getId() == R.id.profileViewEdit) { floatingActionButton.show(); floatingActionButton.setOnClickListener(v -> { DialogFragment newProfileFragment = new NewProfileDialogFragment(); newProfileFragment.show(getFragmentManager(), "new"); }); } }
Example #2
Source File: PDevice.java From PHONK with GNU General Public License v3.0 | 6 votes |
/** * Gets notifications from other apps. * In order to work to must enable the access of notifications in your device settings * * @param callback * @status TOREVIEW */ @PhonkMethod public void onNewNotification(final ReturnInterface callback) { if (!isNotificationServiceRunning()) { showNotificationsManager(); } onNotification = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { ReturnObject ret = new ReturnObject(); ret.put("package", intent.getStringExtra("package")); ret.put("title", intent.getStringExtra("title")); ret.put("text", intent.getStringExtra("text")); callback.event(ret); } }; LocalBroadcastManager.getInstance(getContext()).registerReceiver(onNotification, new IntentFilter("Msg")); }
Example #3
Source File: HostTouchProfile.java From DeviceConnect-Android with MIT License | 6 votes |
@Override public boolean onRequest(final Intent request, final Intent response) { String serviceId = getServiceID(request); // Event registration. EventError error = EventManager.INSTANCE.addEvent(request); if (error == EventError.NONE) { execTouchProfileActivity(serviceId); IntentFilter filter = new IntentFilter(ACTION_TOUCH); LocalBroadcastManager.getInstance(getContext()).registerReceiver(mTouchEventBR, filter); setTouchEventFlag(FLAG_ON_TOUCH_END); setResult(response, DConnectMessage.RESULT_OK); } else { MessageUtils.setInvalidRequestParameterError(response,"Can not register event."); } return true; }
Example #4
Source File: PixivOperate.java From Pixiv-Shaft with MIT License | 6 votes |
public static void postUnFollowUser(int userID) { Retro.getAppApi().postUnFollow( sUserModel.getResponse().getAccess_token(), userID) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new ErrorCtrl<NullResponse>() { @Override public void onNext(NullResponse nullResponse) { Intent intent = new Intent(Params.LIKED_USER); intent.putExtra(Params.ID, userID); intent.putExtra(Params.IS_LIKED, false); LocalBroadcastManager.getInstance(Shaft.getContext()).sendBroadcast(intent); Common.showToast(getString(R.string.cancel_like)); } }); }
Example #5
Source File: ITPDRunFragment.java From InviZible with GNU General Public License v3.0 | 6 votes |
@Override public void onStart() { super.onStart(); //MainFragment do this job for portrait orientation, so return if (btnITPDStart == null) { return; } presenter = new ITPDFragmentPresenter(this); receiver = new ITPDFragmentReceiver(this, presenter); if (getActivity() != null) { IntentFilter intentFilterBckgIntSer = new IntentFilter(RootExecService.COMMAND_RESULT); IntentFilter intentFilterTopFrg = new IntentFilter(TOP_BROADCAST); LocalBroadcastManager.getInstance(getActivity()).registerReceiver(receiver, intentFilterBckgIntSer); LocalBroadcastManager.getInstance(getActivity()).registerReceiver(receiver, intentFilterTopFrg); presenter.onStart(getActivity()); } }
Example #6
Source File: MainActivity.java From wearable with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //get the widgets mybutton = findViewById(R.id.sendbtn); mybutton.setOnClickListener(this); logger = findViewById(R.id.logger); //message handler for the send thread. handler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { Bundle stuff = msg.getData(); logthis(stuff.getString("logthis")); return true; } }); // Register the local broadcast receiver IntentFilter messageFilter = new IntentFilter(Intent.ACTION_SEND); MessageReceiver messageReceiver = new MessageReceiver(); LocalBroadcastManager.getInstance(this).registerReceiver(messageReceiver, messageFilter); }
Example #7
Source File: TorRunFragment.java From InviZible with GNU General Public License v3.0 | 6 votes |
@Override public void onStart() { super.onStart(); //MainFragment do this job for portrait orientation, so return if (btnTorStart == null) { return; } presenter = new TorFragmentPresenter(this); receiver = new TorFragmentReceiver(this, presenter); if (getActivity() != null) { IntentFilter intentFilterBckgIntSer = new IntentFilter(RootExecService.COMMAND_RESULT); IntentFilter intentFilterTopFrg = new IntentFilter(TopFragment.TOP_BROADCAST); LocalBroadcastManager.getInstance(getActivity()).registerReceiver(receiver, intentFilterBckgIntSer); LocalBroadcastManager.getInstance(getActivity()).registerReceiver(receiver, intentFilterTopFrg); presenter.onStart(getActivity()); } }
Example #8
Source File: SettingsFragment.java From android-notification-log with MIT License | 6 votes |
@Override public void onResume() { super.onResume(); if(Util.isNotificationAccessEnabled(getActivity())) { prefStatus.setSummary(R.string.settings_notification_access_enabled); prefText.setEnabled(true); prefOngoing.setEnabled(true); } else { prefStatus.setSummary(R.string.settings_notification_access_disabled); prefText.setEnabled(false); prefOngoing.setEnabled(false); } IntentFilter filter = new IntentFilter(); filter.addAction(NotificationHandler.BROADCAST); LocalBroadcastManager.getInstance(getActivity()).registerReceiver(updateReceiver, filter); update(); }
Example #9
Source File: ErrorReporterEngine.java From mapbox-events-android with MIT License | 6 votes |
public static void sendErrorReports(@NonNull final Context context, @NonNull final ExecutorService executorService) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { LocalBroadcastManager.getInstance(context) .sendBroadcast(new Intent(MapboxTelemetryConstants.ACTION_TOKEN_CHANGED)); } else { try { executorService.execute(new Runnable() { @Override public void run() { ErrorReporterEngine.sendReports(context); } }); } catch (Throwable throwable) { Log.e(LOG_TAG, throwable.toString()); } } }
Example #10
Source File: DebugAccessibilityService.java From DoraemonKit with Apache License 2.0 | 6 votes |
@Override public void onAccessibilityEvent(AccessibilityEvent event) { CharSequence pkgName = event.getPackageName(); if (pkgName == null) { return; } if (!pkgName.equals(getPackageName())) { return; } if (event.getEventType() != AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { return; } if (!isActivityEvent(event)) { return; } AccessibilityNodeInfo info = event.getSource(); if (info == null) { return; } Intent intent = new Intent(BroadcastAction.ACTION_ACCESSIBILITY_UPDATE); intent.putExtra(BundleKey.ACCESSIBILITY_DATA, info); LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent); }
Example #11
Source File: DownloadCardsAdapter.java From Aria2App with GNU General Public License v3.0 | 6 votes |
public DownloadCardsAdapter(Context context, List<DownloadWithUpdate> objs, Listener listener) { super(objs, SortBy.STATUS); this.context = context.getApplicationContext(); this.listener = listener; this.inflater = LayoutInflater.from(context); this.broadcastManager = LocalBroadcastManager.getInstance(context); setHasStableIds(true); receiver = new LocalReceiver(); IntentFilter filter = new IntentFilter(); filter.addAction(NotificationService.EVENT_STOPPED); filter.addAction(NotificationService.EVENT_GET_MODE); broadcastManager.registerReceiver(receiver, filter); bindNotificationService(); }
Example #12
Source File: HostTouchProfile.java From DeviceConnect-Android with MIT License | 5 votes |
@Override public boolean onRequest(final Intent request, final Intent response) { // Event release. EventError error = EventManager.INSTANCE.removeEvent(request); if (error == EventError.NONE) { resetTouchEventFlag(FLAG_ON_DOUBLE_TAP); LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(mTouchEventBR); setResult(response, DConnectMessage.RESULT_OK); } else { MessageUtils.setInvalidRequestParameterError(response,"Can not unregister event."); } return true; }
Example #13
Source File: SimpleTask.java From FairEmail with GNU General Public License v3.0 | 5 votes |
private void cleanup(Context context) { future = null; synchronized (tasks) { tasks.remove(this); if (count) executing--; } LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); lbm.sendBroadcast(new Intent(ACTION_TASK_COUNT).putExtra("count", executing)); Log.i("Remaining tasks=" + tasks.size()); }
Example #14
Source File: InternalBroadcastReceiver.java From prayer-times-android with Apache License 2.0 | 5 votes |
public void register() { IntentFilter filter = new IntentFilter(); if (this instanceof OnStartListener) { filter.addAction(ACTION_ON_START); } if (this instanceof OnTimeTickListener) { filter.addAction(ACTION_TIMETICK); } if (this instanceof OnPrefsChangedListener) { filter.addAction(ACTION_PREFSCHANGED); } LocalBroadcastManager.getInstance(context).registerReceiver(this, filter); }
Example #15
Source File: AdapterNavAccount.java From FairEmail with GNU General Public License v3.0 | 5 votes |
@Override public void onClick(View v) { int pos = getAdapterPosition(); if (pos == RecyclerView.NO_POSITION) return; TupleAccountEx account = items.get(pos); if (account == null) return; LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); lbm.sendBroadcast( new Intent(ActivityView.ACTION_VIEW_FOLDERS) .putExtra("id", account.id)); }
Example #16
Source File: BaseListActivity.java From materialistic with Apache License 2.0 | 5 votes |
@Override public void onBackPressed() { if (!mIsMultiPane || !mFullscreen) { super.onBackPressed(); } else { LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent( WebFragment.ACTION_FULLSCREEN).putExtra(WebFragment.EXTRA_FULLSCREEN, false)); } }
Example #17
Source File: BleProfileService.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onError(@NonNull final BluetoothDevice device, @NonNull final String message, final int errorCode) { final Intent broadcast = new Intent(BROADCAST_ERROR); broadcast.putExtra(EXTRA_DEVICE, bluetoothDevice); broadcast.putExtra(EXTRA_ERROR_MESSAGE, message); broadcast.putExtra(EXTRA_ERROR_CODE, errorCode); LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast); }
Example #18
Source File: ScannerViewModel.java From Bluefruit_LE_Connect_Android_V2 with MIT License | 5 votes |
private void registerGattReceiver() { IntentFilter filter = new IntentFilter(); filter.addAction(BlePeripheral.kBlePeripheral_OnConnecting); filter.addAction(BlePeripheral.kBlePeripheral_OnConnected); filter.addAction(BlePeripheral.kBlePeripheral_OnDisconnected); LocalBroadcastManager.getInstance(getApplication()).registerReceiver(mGattUpdateReceiver, filter); }
Example #19
Source File: IRKitRegisterIRFragment.java From DeviceConnect-Android with MIT License | 5 votes |
/** * 仮想デバイスの状態を更新する. * @param serviceId 仮想デバイスのサービスID */ private void sendEventOnUpdate(final String serviceId) { Activity activity = getActivity(); if (activity == null) { return; } Intent intent = new Intent(IRKitDeviceService.ACTION_VIRTUAL_DEVICE_UPDATED); intent.putExtra(IRKitDeviceService.EXTRA_VIRTUAL_DEVICE_ID, serviceId); LocalBroadcastManager.getInstance(activity).sendBroadcast(intent); }
Example #20
Source File: MainActivity.java From BroadCastReceiver with Apache License 2.0 | 5 votes |
@Override protected void onPause() { //or onDestory() // Unregister since the activity is not visible. This is using the local broadcast, instead of a global. LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver); //the one below unregisters a global receiver. //unregisterReceiver(mReceiver); Log.v(TAG, "receiver should be unregistered"); super.onPause(); }
Example #21
Source File: ReactNativeNotificationsHandlerTest.java From react-native-azurenotificationhub with MIT License | 5 votes |
@Before public void setUp() throws Exception { // Reset mocks reset(mLocalBroadcastManager); reset(mNotificationHubUtil); reset(mBundle); // Prepare mock objects PowerMockito.mockStatic(LocalBroadcastManager.class); when(LocalBroadcastManager.getInstance(mReactApplicationContext)).thenReturn(mLocalBroadcastManager); PowerMockito.mockStatic(ReactNativeNotificationHubUtil.class); when(ReactNativeNotificationHubUtil.getInstance()).thenReturn(mNotificationHubUtil); PowerMockito.mockStatic(ReactNativeUtil.class); PowerMockito.mockStatic(BitmapFactory.class); PowerMockito.mockStatic(Color.class); PowerMockito.mockStatic(PendingIntent.class); PowerMockito.mockStatic(Log.class); mIntentClass = Class.forName("com.reactnativeazurenotificationhubsample.MainActivity"); when(ReactNativeUtil.getMainActivityClass(mReactApplicationContext)).thenReturn(mIntentClass); mWorkerTask = ArgumentCaptor.forClass(Runnable.class); PowerMockito.doNothing().when( ReactNativeUtil.class, "runInWorkerThread", mWorkerTask.capture()); mNotificationBuilder = PowerMockito.mock(NotificationCompat.Builder.class); when(ReactNativeUtil.initNotificationCompatBuilder( any(), any(), any(), any(), anyInt(), anyInt(), anyBoolean())).thenReturn(mNotificationBuilder); mNotification = PowerMockito.mock(Notification.class); when(mNotificationBuilder.build()).thenReturn(mNotification); }
Example #22
Source File: FeedbackActivity.java From shaky-android with Apache License 2.0 | 5 votes |
@Override protected void onResumeFragments() { super.onResumeFragments(); IntentFilter filter = new IntentFilter(); filter.addAction(FeedbackTypeAdapter.ACTION_FEEDBACK_TYPE_SELECTED); filter.addAction(FormFragment.ACTION_SUBMIT_FEEDBACK); filter.addAction(FormFragment.ACTION_EDIT_IMAGE); filter.addAction(DrawFragment.ACTION_DRAWING_COMPLETE); LocalBroadcastManager.getInstance(this).registerReceiver(receiver, filter); }
Example #23
Source File: AlTypingIndicator.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void unSubscribe(Channel channel, Contact contact) { Applozic.unSubscribeToTyping(getContext(), channel, contact); if (mReceiver != null) { LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(mReceiver); mReceiver = null; } }
Example #24
Source File: EHService.java From Easer with GNU General Public License v3.0 | 5 votes |
@Override public void onDestroy() { Logger.v(TAG + "onDestroy"); super.onDestroy(); ServiceUtils.Companion.stopNotification(this); ActivityLogService.Companion.notifyServiceStatus(this, SERVICE_NAME, false, null); mCancelTriggers(); LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver); coreSkillHelper.onDestroy(); unbindService(connection); running = false; Intent intent = new Intent(ACTION_STATE_CHANGED); sendBroadcast(intent); Logger.i(TAG + "destroyed"); }
Example #25
Source File: AppListFragment.java From Shelter with Do What The F*ck You Want To Public License | 5 votes |
void installAppCallback(int result, ApplicationInfoWrapper app, boolean isInstall) { if (result == Activity.RESULT_OK) { String message = getString(isInstall ? R.string.clone_success : R.string.uninstall_success); message = String.format(message, app.getLabel()); Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show(); LocalBroadcastManager.getInstance(getContext()) .sendBroadcast(new Intent(BROADCAST_REFRESH)); } else if (result == ShelterService.RESULT_CANNOT_INSTALL_SYSTEM_APP) { Toast.makeText(getContext(), getString(isInstall ? R.string.clone_fail_system_app : R.string.uninstall_fail_system_app), Toast.LENGTH_SHORT).show(); } }
Example #26
Source File: LocalOAuth2Main.java From DeviceConnect-Android with MIT License | 5 votes |
/** * 認可の結果を受け取るためのLocalBroadcastReceiverを登録します. * * @param context 登録するコンテキスト */ private void register(android.content.Context context) { IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_TOKEN_APPROVAL); filter.addAction(ACTION_OAUTH_ACCEPT); filter.addAction(ACTION_OAUTH_DECLINE); LocalBroadcastManager.getInstance(context).registerReceiver(mBroadcastReceiver, filter); mContext.registerReceiver(mBroadcastReceiver, filter); }
Example #27
Source File: FeedbackActivity.java From shaky-android with Apache License 2.0 | 5 votes |
@Override public void onBackPressed() { Intent intent = new Intent(ACTION_ACTIVITY_CLOSED_BY_USER); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); super.onBackPressed(); }
Example #28
Source File: BleProfileService.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onServicesDiscovered(@NonNull final BluetoothDevice device, final boolean optionalServicesFound) { final Intent broadcast = new Intent(BROADCAST_SERVICES_DISCOVERED); broadcast.putExtra(EXTRA_DEVICE, bluetoothDevice); broadcast.putExtra(EXTRA_SERVICE_PRIMARY, true); broadcast.putExtra(EXTRA_SERVICE_SECONDARY, optionalServicesFound); LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast); }
Example #29
Source File: FcmRegistrationIntentService.java From ETSMobile-Android2 with Apache License 2.0 | 5 votes |
@Override public void onHandleWork(@NonNull Intent intent) { // In the (unlikely) event that multiple refresh operations occur simultaneously, // ensure that they are processed sequentially.x // [START register_for_gcm] // Initially this call goes out to the network to retrieve the token, subsequent calls // are local. // [START get_token] try { Task<InstanceIdResult> instanceId = FirebaseInstanceId.getInstance().getInstanceId(); InstanceIdResult result = Tasks.await(instanceId); Log.i(TAG, "FCM Registration Token: " + result.getToken()); if (ApplicationManager.domaine != null && ApplicationManager.userCredentials != null) { sendRegistrationToServer(result.getToken()); // Subscribe to topic channels subscribeTopics(); // [END get_token] // Notify UI that registration has completed, so the progress indicator can be hidden. Intent registrationComplete = new Intent(Constants.REGISTRATION_COMPLETE); LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete); // [END register_for_fcm] } } catch (ExecutionException | InterruptedException ei) { ei.printStackTrace(); } }
Example #30
Source File: GattServer.java From Bluefruit_LE_Connect_Android_V2 with MIT License | 5 votes |
public GattServer(Context context, Listener listener) { mListener = listener; mBluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE); // Update internal status onBluetoothStateChanged(context); // Set Ble status receiver IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); LocalBroadcastManager.getInstance(context).registerReceiver(mBleAdapterStateReceiver, filter); }