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

The following examples show how to use androidx.localbroadcastmanager.content.LocalBroadcastManager#registerReceiver() . 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: 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 2
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 3
Source File: FragmentBase.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onResume() {
    Log.d("Resume " + this);
    super.onResume();
    updateSubtitle();
    if (finish) {
        getParentFragmentManager().popBackStack();
        finish = false;
    }

    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
    IntentFilter iff = new IntentFilter();
    iff.addAction(ACTION_STORE_ATTACHMENT);
    iff.addAction(ACTION_STORE_ATTACHMENTS);
    lbm.registerReceiver(receiver, iff);
}
 
Example 4
Source File: ServiceLifecycleTest.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    Context context = InstrumentationRegistry.getTargetContext();
    mServiceIntent = new Intent(context, TestService.class);
    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TestService.ACTION_LOG_EVENT);

    // Overcautiousness: each EventLogger has its own events list, so one bad test won't spoil
    // others.
    mLoggerEvents = new ArrayList<>();
    mLogger = new EventLogger(mLoggerEvents);
    localBroadcastManager.registerReceiver(mLogger, intentFilter);

}
 
Example 5
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 6
Source File: ActivityBilling.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
    IntentFilter iff = new IntentFilter();
    iff.addAction(ACTION_PURCHASE);
    iff.addAction(ACTION_PURCHASE_CHECK);
    iff.addAction(ACTION_PURCHASE_ERROR);
    lbm.registerReceiver(receiver, iff);

    //if (billingClient != null && billingClient.isReady())
    //    queryPurchases();
}
 
Example 7
Source File: ActivityBilling.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
    IntentFilter iff = new IntentFilter();
    iff.addAction(ACTION_PURCHASE);
    iff.addAction(ACTION_PURCHASE_CHECK);
    iff.addAction(ACTION_PURCHASE_ERROR);
    lbm.registerReceiver(receiver, iff);

    if (billingClient != null && billingClient.isReady())
        queryPurchases();
}
 
Example 8
Source File: MainActivity.java    From quickstart-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    updateUI(mAuth.getCurrentUser());

    // Register receiver for uploads and downloads
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this);
    manager.registerReceiver(mBroadcastReceiver, MyDownloadService.getIntentFilter());
    manager.registerReceiver(mBroadcastReceiver, MyUploadService.getIntentFilter());
}
 
Example 9
Source File: ReactNativeNotificationHubModule.java    From react-native-azurenotificationhub with MIT License 5 votes vote down vote up
public ReactNativeNotificationHubModule(ReactApplicationContext reactContext) {
    super(reactContext);
    this.mReactContext = reactContext;
    this.mLocalBroadcastReceiver = new LocalBroadcastReceiver();
    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(reactContext);
    localBroadcastManager.registerReceiver(mLocalBroadcastReceiver, new IntentFilter(ReactNativeRegistrationIntentService.TAG));
    localBroadcastManager.registerReceiver(mLocalBroadcastReceiver, new IntentFilter(ReactNativeNotificationsHandler.TAG));
    reactContext.addLifecycleEventListener(this);
    reactContext.addActivityEventListener(this);
}
 
Example 10
Source File: MainApp.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private void registerLocalBroadcastReceiver() {
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
    lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_TREATMENT));
    lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_CHANGED_TREATMENT));
    lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_REMOVED_TREATMENT));
    lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_FOOD));
    lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_CHANGED_FOOD));
    lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_REMOVED_FOOD));
    lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_SGV));
    lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_PROFILE));
    lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_STATUS));
    lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_MBG));
    lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_DEVICESTATUS));
    lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_CAL));

    //register alarms
    lbm.registerReceiver(alarmReceiver, new IntentFilter(Intents.ACTION_ALARM));
    lbm.registerReceiver(alarmReceiver, new IntentFilter(Intents.ACTION_ANNOUNCEMENT));
    lbm.registerReceiver(alarmReceiver, new IntentFilter(Intents.ACTION_CLEAR_ALARM));
    lbm.registerReceiver(alarmReceiver, new IntentFilter(Intents.ACTION_URGENT_ALARM));

    this.timeDateOrTZChangeReceiver = new TimeDateOrTZChangeReceiver();
    this.timeDateOrTZChangeReceiver.registerBroadcasts(this);

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION );
    registerReceiver(new NetworkChangeReceiver(), intentFilter);
    registerReceiver(new ChargingStateReceiver(), new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
 
Example 11
Source File: AppLinkTest.java    From Bolts-Android with MIT License 5 votes vote down vote up
public void testGeneralMeasurementEventsBroadcast() throws Exception {
  Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
  i.putExtra("foo", "bar");
  ArrayList<String> arr = new ArrayList<>();
  arr.add("foo2");
  arr.add("bar2");
  i.putExtra("foobar", arr);
  Map<String, String> other = new HashMap<>();
  other.put("yetAnotherFoo", "yetAnotherBar");

  final CountDownLatch lock = new CountDownLatch(1);
  final String[] receivedStrings = new String[5];
  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("foo");
          receivedStrings[2] = eventArgs.getString("foobar");
          receivedStrings[3] = eventArgs.getString("yetAnotherFoo");
          receivedStrings[4] = eventArgs.getString("intentData");
          lock.countDown();
        }
      },
      new IntentFilter("com.parse.bolts.measurement_event")
  );

  MeasurementEvent.sendBroadcastEvent(instrumentation.getTargetContext(), "myEventName", i, other);
  lock.await(20000, TimeUnit.MILLISECONDS);

  assertEquals("myEventName", receivedStrings[0]);
  assertEquals("bar", receivedStrings[1]);
  assertEquals((new JSONArray(arr)).toString(), receivedStrings[2]);
  assertEquals("yetAnotherBar", receivedStrings[3]);
  assertEquals("http://www.example.com", receivedStrings[4]);
}
 
Example 12
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]);
  }