Can a LocalBroadcastManager send Intent to global BroadcastReceivers in the same App? - broadcastreceiver

Can a LocalBroadcastManager send an Intent to a globally registered BroadcastReceiver if it resides in the same App? Or do I have to use context.sendBroadcast() for that?

No. LocalBroadcastManager cannot send Intent to global BroadcastReceivers.
Explanation:
LocalBroadcastManager has a private HashMap, in which it maps BroadcastReceiver to ArrayList<IntentFilter>, when registerReceiver method is called explicitly using any context within application. It does not hold any record of global BroadcastReceivers declared in AndroidManifest.xml. So, LocalBroadcastManager won't send Intent to global BroadcastReceivers.
See the below screenshot captured while I debugged LocalBroadcastReceiver from my application which has three BroadcastReceivers declared globally in AndroidManifest.xml

Related

How to simulate the behaviour when the user loads the app from the URL in the browser's address bar

I'm writing a Flutter web application and I want to write a test on the behavior when the user loads the app when he types the URL in the browser's address bar.
For example I would like my test to behave as if the user typed /my/path.
How can I do that?
If you look at the class PlatformDispatcher (which olds a singleton instance .instance) you can see a getter defaultRouteName.
The route or path that the embedder requested when the application was launched.
This will be the string "/" if no particular route was requested.
So when your user starts your application with the url /my/path, PlatformDispatcher.instance.defaultRouteName with be equal to '/my/path'.
How to mock it?
You can also access the PlatformDispatcher.instance from WidgetsBinding.instance.platformDispatcher and if you read the doc of the getter platformDispatcher, you'll read:
A subclass of BindingBase, such as TestWidgetsFlutterBinding, can override this accessor to return a different ui.PlatformDispatcher implementation.
In the context of a testWidgets
testWidgets('', (WidgetTester test) async {});
tester.binding gives you access to the TestWidgetsFlutterBinding which is the binding used by widgets library tests. In this test binding, the platformDispatcher is overridden and a TestPlatformDispatcher with a setter defaultRouterNameTestValue that you can use to mock the defaultRouteName getter.
TL;DR
You can use:
tester.binding.platformDispatcher.defaultRouteNameTestValue = '/my/path'
to test the behavior when the user loads the app when he types the URL /my/path in the browser's address bar.

How do I know I am being called from a progresive web app?

I've been following the guidance on google to create a PWA, but I am interested if there are any conventions to communicate with your data server that you are being called by a PWA. Is the easiest thing to add a parameter to the request i.e.
var dataUrl = 'https://query.myapi.com/v1/get?source=pwa';
and then check the source parameter? Or should I add to the request header?
In your code
if (window.matchMedia('(display-mode: standalone)').matches) {
// do things here
// set a variable to be used when calling something
// e.g. call Google Analytics to track standalone use
}
** Assumption made that you are also setting up your app to be added to the users home screen as a shortcut
You have to pass in the traffic source to Google Analytics indicating its from PWA. Refer this answer on more details.

Starting a socket on a settings page and allowing the MainPage to access it WP8

I have class that the MainPage of my app can access, but it requires user input for the ip address so I've setup a new page rather like a settings page, if I add the same code as the MainPage the socket works as expected but I only want to send the connect command from the settings page then allow the MainPage to send the values to the socket... if I connect on settings page and then try to send data from MainPage I get "Socket not initialized" when it was as it was done from the Settings Page, can anybody explain whats happening here and possible solutions? it's like the app page is two different 'ecosystems' and the two can't combine methods and vars etc?
Am I looking into this wrong and yes you've guessed it I'm hopelessly new to all this!
Each page in a WP app is a separate class. So where is your Socket object declared? If you declared it as an instance variable of the MainPage class (for example), it would not be in scope when the Settings page is active (or vice versa).
To allow both pages to reference the same instance of Socket, you can declare it as a public member in App class. And you'll probably want to declare it static as is done with App.RootFrame in the automagically generated app templates, to make it easy to reference.

ShareKit for iphone - SHKShareTypeText

I am using ShareKit for iphone to share some text in facebook. Can any one tell me which delegate is called after publishing the text successfully. I need this to inform the user that his action was successful.
The shareDelegate property in SHKSharer isn't the easiest to get to and change, but there are notifications sent from the delegate methods of SHKSharer, one for each of the methods: SHKSendDidStartNotification, SHKSendDidFinish, SHKSendDidCancel, SHKSendDidFailWithError. Observing these notifications turns out to be a simple way of listening for the outcome of sharing.
See shareDelegate property of SHKSharer . All the concrete sharers (e.g. SHKFacebook) extend this base class.
Having said that, I'm not sure where you set a class to be the delegate using ShareKit's public API (so I'm not claiming this to be a complete answer).

How to receive UIAccessibilityNotifications in iPhone App

I'm interested in capturing UI changes in my application programmatically and thought that the UIAccessibility protocol may help. I've found how to post UIAccessibilityLayoutChangedNotification and UIAccessibilityScreenChangedNotification but I'm not sure how to register to receive these notifications.
I've tried using NSNotificationCenter, but the name param expects a string, while the two notifications above are of the type UIAccesibilityNotifications which is an int.
Any idea how to register for these notifications?
Thanks!
That's a great question! Unfortunately you cannot receive these "notifications" without affecting normal behavior. (i.e. "no you can't")
If you disassemble UIKit, you'll find UIAccessibilityPostNotification is implemented like this:
static void (*__UIAccessibilityBroadcastCallback)(UIAccessibilityNotifications notification, id argument);
void UIAccessibilityPostNotification(UIAccessibilityNotifications notification, id argument) {
__UIAccessibilityBroadcastCallback (notification, argument);
}
That means these accessibility "notifications" aren't any normal notifications. Rather, they are just parameters to an internal callback function. How the callback function is implemented depends on the accessibility bundle you're using.
You can replace the callback function with your own using the undocumented API _UIAccessibilitySetBroadcastCallback:
void _UIAccessibilitySetBroadcastCallback(void (*replacement)(UIAccessibilityNotifications notification, id argument)) {
__UIAccessibilityBroadcastCallback = replacement;
}
However, there isn't a corresponding "get" function (not even private), so once you set it, the original listeners cannot be notified again.