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(
var
LToast: JToast;
LMsg: JCharSequence;
LMsg := StrToJCharSequence(
'WIFI state changed!'
);
LToast := TJToast
JavaClass
makeText(SharedActivityContext, LMsg,
TJToast
LENGTH_LONG);
LToast
show;
end
;
Button1Click(Sender: TObject);
LBroadcastReceiver: JBroadcastReceiver;
LFilter: JIntentFilter;
LBroadcastReceiver := BroadcastReceiver1
as
JBroadcastReceiver;
LFilter := TJIntentFilter
init;
LFilter
addAction(TJWifiManager
WIFI_STATE_CHANGED_ACTION);
SharedActivityContext
registerReceiver(LBroadcastReceiver, LFilter);
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