Java Code Examples for androidx.localbroadcastmanager.content.LocalBroadcastManager#getInstance()

The following examples show how to use androidx.localbroadcastmanager.content.LocalBroadcastManager#getInstance() . 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: ActivityView.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
    IntentFilter iff = new IntentFilter();
    iff.addAction(ACTION_VIEW_FOLDERS);
    iff.addAction(ACTION_VIEW_MESSAGES);
    iff.addAction(ACTION_SEARCH);
    iff.addAction(ACTION_VIEW_THREAD);
    iff.addAction(ACTION_EDIT_FOLDER);
    iff.addAction(ACTION_EDIT_ANSWERS);
    iff.addAction(ACTION_EDIT_ANSWER);
    iff.addAction(ACTION_EDIT_RULES);
    iff.addAction(ACTION_EDIT_RULE);
    lbm.registerReceiver(receiver, iff);

    checkUpdate(false);
    checkIntent();
}
 
Example 2
Source File: ActivitySetup.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
    IntentFilter iff = new IntentFilter();
    iff.addAction(ACTION_QUICK_GMAIL);
    iff.addAction(ACTION_QUICK_OAUTH);
    iff.addAction(ACTION_QUICK_SETUP);
    iff.addAction(ACTION_VIEW_ACCOUNTS);
    iff.addAction(ACTION_VIEW_IDENTITIES);
    iff.addAction(ACTION_EDIT_ACCOUNT);
    iff.addAction(ACTION_EDIT_IDENTITY);
    iff.addAction(ACTION_MANAGE_LOCAL_CONTACTS);
    iff.addAction(ACTION_MANAGE_CERTIFICATES);
    iff.addAction(ACTION_IMPORT_CERTIFICATE);
    iff.addAction(ACTION_SETUP_ADVANCED);
    iff.addAction(ACTION_SETUP_MORE);
    lbm.registerReceiver(receiver, iff);
}
 
Example 3
Source File: FBaseMessagingService.java    From tindroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onNewToken(@NonNull final String refreshedToken) {
    super.onNewToken(refreshedToken);
    Log.d(TAG, "Refreshed token: " + refreshedToken);

    // Send token to the server.
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
    Intent intent = new Intent("FCM_REFRESH_TOKEN");
    intent.putExtra("token", refreshedToken);
    lbm.sendBroadcast(intent);

    // The token is currently retrieved in co.tinode.tindroid.Cache.
}
 
Example 4
Source File: AdapterNavUnified.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    int pos = getAdapterPosition();
    if (pos == RecyclerView.NO_POSITION)
        return;

    TupleFolderUnified folder = items.get(pos);
    if (folder == null || folder.type == null)
        return;

    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
    lbm.sendBroadcast(
            new Intent(ActivityView.ACTION_VIEW_MESSAGES)
                    .putExtra("type", folder.type));
}
 
Example 5
Source File: SimpleTask.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
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 6
Source File: AdapterAttachment.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
private void onSave(EntityAttachment attachment) {
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
    lbm.sendBroadcast(
            new Intent(FragmentMessages.ACTION_STORE_ATTACHMENT)
                    .putExtra("id", attachment.id)
                    .putExtra("name", Helper.sanitizeFilename(attachment.name))
                    .putExtra("type", attachment.getMimeType()));
}
 
Example 7
Source File: NetworkChangedReceiver.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * LocalBroadcastManagerからローカルブロードキャスト受信用のレシーバーを登録解除するためのヘルパーメソッド
 * LocalBroadcastManager#unregisterReceiverを自前で呼び出すかNetworkChangedReceiver#unregisterを呼び出しても良い
 * @param context
 * @param receiver
 */
public static void unregisterLocal(@NonNull final Context context,
	@NonNull final NetworkChangedReceiver receiver) {

	if (DEBUG) Log.v(TAG, "unregisterLocal:");
	final LocalBroadcastManager broadcastManager
		= LocalBroadcastManager.getInstance(context.getApplicationContext());
	try {
		broadcastManager.unregisterReceiver(receiver);
	} catch (final Exception e) {
		// ignore
	}
}
 
Example 8
Source File: FirebaseAppTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  targetContext = InstrumentationRegistry.getTargetContext();
  backgroundDetector = BackgroundDetector.getInstance();
  // Used by Scion internally.
  // Scion.testOnlySetDefaultFactory(new ScionFactory(targetContext));
  localBroadcastManager = LocalBroadcastManager.getInstance(targetContext);
  // Force background detector state to foreground
  backgroundDetector.onActivityResumed(null);
}
 
Example 9
Source File: AdapterNavAccount.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@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 10
Source File: BluetoothMedic.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@RequiresApi(21)
private void initializeWithContext(Context context) {
    if (this.mAdapter == null || this.mLocalBroadcastManager == null) {
        BluetoothManager manager = (BluetoothManager)context.getSystemService(Context.BLUETOOTH_SERVICE);
        if(manager == null) {
            throw new NullPointerException("Cannot get BluetoothManager");
        } else {
            this.mAdapter = manager.getAdapter();
            this.mLocalBroadcastManager = LocalBroadcastManager.getInstance(context);
        }
    }
}
 
Example 11
Source File: UploadCancelFragment.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onCancel(@NonNull final DialogInterface dialog) {
	final LocalBroadcastManager manager = LocalBroadcastManager.getInstance(requireContext());
	final Intent pauseAction = new Intent(DfuService.BROADCAST_ACTION);
	pauseAction.putExtra(DfuService.EXTRA_ACTION, DfuService.ACTION_RESUME);
	manager.sendBroadcast(pauseAction);
}
 
Example 12
Source File: Core.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
private static void reportNewMessage(Context context, EntityAccount account, EntityFolder folder, EntityMessage message) {
    // Prepare scroll to top
    if (!message.ui_seen && !message.ui_hide &&
            message.received > account.created) {
        Intent report = new Intent(ActivityView.ACTION_NEW_MESSAGE);
        report.putExtra("folder", folder.id);
        report.putExtra("unified", folder.unified);
        Log.i("Report new id=" + message.id + " folder=" + folder.name + " unified=" + folder.unified);

        LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
        lbm.sendBroadcast(report);
    }
}
 
Example 13
Source File: WhatsAppStickersPlugin.java    From flutter_whatsapp_stickers with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private WhatsAppStickersPlugin(Registrar registrar, MethodChannel channel) {
    this.registrar = registrar;
    this.channel = channel;

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(StickerPackActivity.ACTION_STICKER_PACK_RESULT);
    intentFilter.addAction(StickerPackActivity.ACTION_STICKER_PACK_ERROR);
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(registrar.context());
    manager.registerReceiver(this, intentFilter);
}
 
Example 14
Source File: FragmentBase.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPause() {
    Log.d("Pause " + this);
    super.onPause();

    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
    lbm.unregisterReceiver(receiver);
}
 
Example 15
Source File: StartTimerUtils.java    From abnd-track-pomodoro-timer-app with MIT License 4 votes vote down vote up
/**
 * Update MainActivity Elements through  broadcast
 */
private static void sendBroadcast(Context context) {
    LocalBroadcastManager completedBroadcastManager = LocalBroadcastManager.getInstance(context);
    completedBroadcastManager.sendBroadcast(
            new Intent(START_ACTION_BROADCAST));
}
 
Example 16
Source File: AppLinkTest.java    From Bolts-Android with MIT License 4 votes vote down vote up
public void testAppLinkNavInEventBroadcast() throws Exception {
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
    Bundle appLinkData = new Bundle();
    appLinkData.putString("target_url", "http://www.example2.com");
    Bundle appLinkRefererData = new Bundle();
    appLinkRefererData.putString("url", "referer://");
    appLinkRefererData.putString("app_name", "Referrer App");
    appLinkRefererData.putString("package", "com.bolts.referrer");
    appLinkData.putBundle("referer_app_link", appLinkRefererData);
    Bundle applinkExtras = new Bundle();
    applinkExtras.putString("token", "a_token");
    appLinkData.putBundle("extras", applinkExtras);
    i.putExtra("al_applink_data", appLinkData);

    final CountDownLatch lock = new CountDownLatch(1);
    final String[] receivedStrings = new String[7];
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(instrumentation.getTargetContext());
    manager.registerReceiver(
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            String eventName = intent.getStringExtra("event_name");
            Bundle eventArgs = intent.getBundleExtra("event_args");
            receivedStrings[0] = eventName;
            receivedStrings[1] = eventArgs.getString("targetURL");
            receivedStrings[2] = eventArgs.getString("inputURL");
            receivedStrings[3] = eventArgs.getString("refererURL");
            receivedStrings[4] = eventArgs.getString("refererAppName");
            receivedStrings[5] = eventArgs.getString("extras/token");
            receivedStrings[6] = eventArgs.getString("sourceApplication");
            lock.countDown();
          }
        },
        new IntentFilter("com.parse.bolts.measurement_event")
    );

    Uri targetUrl = AppLinks.getTargetUrlFromInboundIntent(instrumentation.getTargetContext(), i);
//    lock.await(2000, TimeUnit.MILLISECONDS);
    lock.await();

    assertEquals("al_nav_in", receivedStrings[0]);
    assertEquals("http://www.example2.com", receivedStrings[1]);
    assertEquals("http://www.example.com", receivedStrings[2]);
    assertEquals("referer://", receivedStrings[3]);
    assertEquals("Referrer App", receivedStrings[4]);
    assertEquals("a_token", receivedStrings[5]);
    assertEquals("com.bolts.referrer", receivedStrings[6]);
  }
 
Example 17
Source File: BroadcastManager.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
public static BroadcastManager getInstance(Context ctx) {
    BroadcastManager broadcastManager = new BroadcastManager();
    broadcastManager.localBroadcastManager = LocalBroadcastManager.getInstance(ctx.getApplicationContext());
    return broadcastManager;
}
 
Example 18
Source File: StopTimerUtils.java    From abnd-track-pomodoro-timer-app with MIT License 4 votes vote down vote up
/**
 * Update MainActivity Elements through  broadcast
 */
private static void sendBroadcast(Context context) {
    LocalBroadcastManager completedBroadcastManager = LocalBroadcastManager.getInstance(context);
    completedBroadcastManager.sendBroadcast(
            new Intent(COMPLETE_ACTION_BROADCAST));
}
 
Example 19
Source File: ActivityView.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onPause() {
    super.onPause();
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
    lbm.unregisterReceiver(receiver);
}
 
Example 20
Source File: ActivityView.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onDestroy() {
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
    lbm.unregisterReceiver(creceiver);
    super.onDestroy();
}