Einzelnen Beitrag anzeigen

Gruber_Hans_12345

Registriert seit: 14. Aug 2004
1.441 Beiträge
 
Delphi 2007 Professional
 
#1

Android / BroadcastListener / Zebra Scanner / DataWedge

  Alt 9. Apr 2024, 09:17
Hallo ich versuche gerade in einer App den Intent von der DataWedge des ZEbra Scanners zu bekommen.

Dazu habe ich in meinem manifest
Code:
            <intent-filter>
            <action android:name="org.test.intent.barcode" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
Mein code in Delphi sieht so aus
Code:
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;
Im Datawegde von ZEbra habe ich
Code:
Profile Enabled
Associated Apps: "com.embarcadero.firemonkey.FMXNativeActivity | com.embarcadero.test"
Barcode Input: Enabled
Keystroke Output: Disabled
Intent Output section:
  Intent action: org.test.intent.barcode
  Intent category: android.intent.category.DEFAULT (oder leer gelassen)
  Intent delivery: startActivity (bzw Broadcast intent)
  Component Information: [empty]
Hat da noch wer einen Tipp was da noch wo falsch sein könnte?
In das onReceive geht er nie rein
Gruss Hans

2B or not 2B, that is FF
  Mit Zitat antworten Zitat