About the author
I've recently completed the Delphi IDE BroadcastReceiver plug-in for Android. The BroadcastReceiver plug-in is part of the Android2DelphiImport product.
This plug-in enables your Delphi FireMonkey Mobile application to have BroadcastReceivers in it.
Here's what the Delphi IDE looks like with the plugin.
The plug-in is simple to use. After installing the plug-in, an "Android" category appears in the Tool Palette. From the tool palette, drag and drop the TBroadcastReceiver component onto your form, and then, you register your BroadcastReceiver.
Here's what it looks like to register the receiver, and to show a Toast:
procedure TForm1.BroadcastReceiver1Receive(AContext: JContext; AIntent: JIntent); begin CallInUIThread(procedure var LToast: JToast; LMsg: JCharSequence; begin LMsg := StrToJCharSequence('WIFI state changed!'); LToast := TJToast.JavaClass.makeText(SharedActivityContext, LMsg, TJToast.JavaClass.LENGTH_LONG); LToast.show; end); end; procedure TForm1.Button1Click(Sender: TObject); var LBroadcastReceiver: JBroadcastReceiver; LFilter: JIntentFilter; begin LBroadcastReceiver := BroadcastReceiver1 as JBroadcastReceiver; LFilter := TJIntentFilter.JavaClass.init; LFilter.addAction(TJWifiManager.JavaClass.WIFI_STATE_CHANGED_ACTION); SharedActivityContext.registerReceiver(LBroadcastReceiver, LFilter); end;
Build the project, and deploy it to your mobile phone! It's as simple as it can be!
In the example above, one clicks touches the button, which registers the BroadcastReceiver. Then, toggle the WIFI state, and the Toast shows on screen.
With the BroadcastReceiver plugin , it is easy to write a Bluetooth discovery application with Delphi