type
TDataWedgeDataEvent = procedure(Sender: TObject; const Data: string) of object;
TDataWedgeBroadcastListener = class(TJavaLocal, JFMXBroadcastReceiverListener)
private
FReceiver: JBroadcastReceiver;
FOnData: TDataWedgeDataEvent;
public
{ JFMXBroadcastReceiverListener }
procedure onReceive(context: JContext; intent: JIntent); cdecl;
public
constructor Create;
destructor Destroy; override;
property OnData: TDataWedgeDataEvent read FOnData write FOnData;
end;
constructor TDataWedgeBroadcastListener.Create;
var
LIntentFilter: JIntentFilter;
begin
inherited;
FReceiver := TJFMXBroadcastReceiver.JavaClass.init(Self);
LIntentFilter := TJIntentFilter.JavaClass.init;
LIntentFilter.addAction(StringToJString('org.test.intent.barcode'));
//LIntentFilter.addCategory(StringToJString('android.intent.category.DEFAULT'));
TAndroidHelper.Context.registerReceiver(FReceiver, LIntentFilter);
frTest.meDebug.Lines.Add('INIT OK');
end;
destructor TDataWedgeBroadcastListener.Destroy;
begin
TAndroidHelper.Context.unregisterReceiver(FReceiver);
inherited;
end;
procedure TDataWedgeBroadcastListener.onReceive(context: JContext; intent: JIntent);
var
data : string;
begin
frTest.meDebug.Lines.Add('onReceive');
data := JStringToString(intent.getStringExtra(StringToJString('
com.symbol.datawedge.data_string')));
frTest.meDebug.Lines.Add('onReceive : "'+data+'"');
if (intent <> nil) and Assigned(FOnData) then
FOnData(Self, data);
end;
var
dw : TDataWedgeBroadcastListener;
procedure TfrTest.Button4Click(Sender: TObject);
begin
dw := TDataWedgeBroadcastListener.Create;
//
end;