-
Content Count
22 -
Joined
-
Last visited
Community Reputation
1 NeutralRecent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
How to call onActivityResult of my activity?/java2op not generating some classes
NecoArc replied to NecoArc's topic in FMX
I tried that, but it didn’t work. So, checking the logs, I attempted some additional fixes. First, I found the class codescanner.SetActivity inside my .jar file: package br.com.gertec.easylayer.codescanner; import android.content.Intent; import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; import br.com.gertec.easylayer.R; public class SetActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.activity_set); Intent intent = this.getIntent(); String s = intent.getStringExtra("result"); if (s != null) { Intent returnIntent = new Intent(); returnIntent.putExtra("content", s); this.setResult(-1, returnIntent); this.finish(); } else { this.finish(); } } Then I implemented the interface in my .jni file: JSetActivity = interface; JSetActivityClass = interface(JObjectClass) ['{D0B8C7AF-92C5-4BB5-8E1A-B76164E7AB10}'] end; [JavaSignature('br/com/gertec/easylayer/codescanner/SetActivity')] JSetActivity = interface(JObject) ['{EBB78E1F-92A4-4E1E-B55C-67130FCEB2A3}'] procedure onCreate(bundle: JBundle); cdecl; end; TJSetActivity = class(TJavaGenericImport<JSetActivityClass, JSetActivity>) end; TRegTypes.RegisterType('android.jni.easylayersk210.JSetActivity', TypeInfo(android.jni.easylayersk210.JSetActivity)); However, I don’t think my declaration is correct. SetActivity extends AppCompatActivity, but I can’t extend this class properly in Delphi. What I think it should be, but I couldn’t make it work because delphi do not recognize JAppCompatActivity, or i didn't find the correct uses path for it JSetActivityClass = interface(JAppCompatActivityClass) JSetActivity = interface(JAppCompatActivity) After this change, the log showed that I need to declare the activity: 09-26 10:51:28.083 I/ActivityTaskManager(1070): START u0 {cmp=com.embarcadero.Project1/br.com.gertec.easylayer.codescanner.SetActivity (has extras)} from uid 10129 09-26 10:51:28.086 E/JavaBinder(21949): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.embarcadero.Project1/br.com.gertec.easylayer.codescanner.SetActivity}; have you declared this activity in your AndroidManifest.xml, or does your intent not match its declared <intent-filter>? 09-26 10:51:28.086 E/JavaBinder(21949): at br.com.gertec.easylayer.codescanner.CodeScanner$1.onResult(CodeScanner.java:281) so i did <activity android:name="br.com.gertec.easylayer.codescanner.SetActivity" android:exported="true"> </activity> Now, instead of the previous error, the app crashes, saying that codescanner.SetActivity closed the app due to timeout, because it didn’t find the activity to return the result, i think. 09-26 11:05:35.026 W/ActivityTaskManager( 1070): Force finishing activity com.embarcadero.Project3/br.com.gertec.easylayer.codescanner.SetActivity 0 09-26 11:05:35.527 W/ActivityTaskManager( 1070): Activity top resumed state loss timeout for ActivityRecord{6f4eb43 u0 com.embarcadero.Project3/br.com.gertec.easylayer.codescanner.SetActivity} t272 f}} 09-26 11:05:35.528 W/ActivityTaskManager( 1070): Activity pause timeout for ActivityRecord{6f4eb43 u0 com.embarcadero.Project3/br.com.gertec.easylayer.codescanner.SetActivity} t272 f}} idk what i can do anymore -
How to call onActivityResult of my activity?/java2op not generating some classes
NecoArc posted a topic in FMX
I’m working with the TOPWISE SK210 device, which is a mini kiosk with a built-in printer and barcode scanner. Here in Brazil, this device is distributed by Gertec, and they provided me with the .jar files and the device manuals. I’m currently trying to integrate the scanner into a Delphi 12 test application. I can successfully call the scanner and trigger a reading, but I cannot retrieve the scanned result. Below is my Delphi code: procedure TForm1.FormCreate(Sender: TObject); begin // Registra o listener para interceptar mensagens de resultado de atividade FMessageSubscriptionID := TMessageManager.DefaultManager.SubscribeToMessage(TMessageResultNotification, HandleActivityMessage); FScannerAtivo := False; end; procedure TForm1.Button1Click(Sender: TObject); var scanner: JCodeScanner; config: JScanConfig; begin Activity := TAndroidHelper.Activity; if not Assigned(Activity) then begin LogDebug('ERRO'); Exit; end; scanner := TJCodeScanner.JavaClass.getInstance(Activity); scanner.scanCode(Activity); end; procedure TForm1.HandleActivityMessage(const Sender: TObject; const M: TMessage); var ResultMsg: TMessageResultNotification; Intent: JIntent; ExtraString: JString; begin if not (M is TMessageResultNotification) then begin Exit; end; ResultMsg := TMessageResultNotification(M); if ResultMsg.ResultCode = TJActivity.JavaClass.RESULT_OK then begin logDebug('it work!') end else if ResultMsg.ResultCode = TJActivity.JavaClass.RESULT_CANCELED then begin logDebug('did not work') end; end; For comparison, here is the Java example that works as expected: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_code_scanner); codeScanner = CodeScanner.getInstance(this); btnStart = findViewById(R.id.btnStart); btnStart.setOnClickListener(view -> { codeScanner.scanCode(this); }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { String content = data.getStringExtra("content"); if (content != null) { consultaOrder.add(content); adapter.notifyDataSetChanged(); } }else { super.onActivityResult(requestCode, resultCode, data); } } Problem When running the Delphi code, the HandleActivityMessage method is always triggered with TJActivity.JavaClass.RESULT_CANCELED. It never returns RESULT_OK, so I cannot capture the scan result. Using Logcat, I found the following error message: 09-25 16:56:43.681 I/ActivityTaskManager( 1063): START u0 {cmp=com.embarcadero.Project1/br.com.gertec.easylayer.codescanner.SetActivity (has extras)} from uid 10126 09-25 16:56:43.685 E/JavaBinder(28668): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.embarcadero.Project1/br.com.gertec.easylayer.codescanner.SetActivity}; have you declared this activity in your AndroidManifest.xml, or does your intent not match its declared <intent-filter>? 09-25 16:56:43.685 E/JavaBinder(28668): at br.com.gertec.easylayer.codescanner.CodeScanner$1.onResult(CodeScanner.java:281) Investigation After checking, I noticed that my JNI file generated by java2op does not include codescanner.SetActivity. When I regenerated the JNI bindings using java2op, I confirmed that it was not created because of the following issue: br.com.gertec.easylayer.codescanner.SetActivity: the parent class (androidx.appcompat.app.AppCompatActivity) is not found Essentially, the problem seems to be that the SetActivity class is missing from my Delphi project because its parent (androidx.appcompat.app.AppCompatActivity) is not being resolved during JNI generation. does someone know what i can do to solve it? thanks in advance everyone -
FMX on mobile: Best practice to handle touch scroll of components?
NecoArc replied to Hans♫'s topic in FMX
thank you hans! this revelation about the ownership of scrolls just saved my life i couldn't unsderstand why one of my projects the scroll was working and on the other project was not working -
problem integrating AAR from manufacturer startup-runtime maybe not working (?)
NecoArc replied to NecoArc's topic in FMX
yeah i notice that extra space after the print, i made some test without it and it keeps crashing the aplication from what i've understood putting any kind of provider tag on the manifest.template.xml just break the application so i took it out before finding a solution then we can conclude that the tag is not necessary but still in some other situation it may be necessary since my solution does not use the native startup runtime (but I don't know if it would be possible because simply adding the provider tag breaks the application) i tested with other types of tag and they were ok -
problem integrating AAR from manufacturer startup-runtime maybe not working (?)
NecoArc replied to NecoArc's topic in FMX
So after a lot of struggle, I finally managed to make this damn thing work. The real issue was the startup-runtime, and I still don’t know how to make it run automatically. I noticed that in the JNI I had, the classes that needed the startup-runtime were commented out, as if java2op hadn’t created their interfaces. To fix the problem, I took the startup-runtime-1.1.1.jar from Embarcadero’s folder and created a new JNI along with this .jar. Right away, I saw that the interfaces using startup-runtime were no longer commented. But that still wasn’t enough to make it work—I had to manually call the methods created by the startup-runtime in Delphi. In my case: jConfigInitializer := TJConfigFileInitializer.Create; usb := TJConUSB.Create; usb.create(TAndroidHelper.Context); and after that it worked -
problem integrating AAR from manufacturer startup-runtime maybe not working (?)
NecoArc replied to NecoArc's topic in FMX
nah it just crashes bro 😕 even if i only add the provider tag without the meta-data the aplication just close when starting -
problem integrating AAR from manufacturer startup-runtime maybe not working (?)
NecoArc replied to NecoArc's topic in FMX
Well now my application crashes instantly when I open it I think this is the right way -
problem integrating AAR from manufacturer startup-runtime maybe not working (?)
NecoArc posted a topic in FMX
I have an FMX self-service application designed to run on kiosks/tablets with printers and scanners. The application already works on various device models by integrating with their respective AAR/JAR libraries provided by the manufacturers (extracting the .jar files and generating the JNI interface using java2op). This past month, I have been working on integrating two devices sent by a new manufacturer: the Mini Kiosk Model and the Plus Kiosk Model. According to the manufacturer, the same AAR and method calls are used for both devices. On the Mini Kiosk, I was able to make everything work without any issues. However, on the Plus Kiosk, which should work the same way, Delphi returns the following error: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.HashMap android.hardware.usb.UsbManager.getDeviceList()' on a null object reference. So i created a test project in Java that worked fine on both devices, the issue is not with the AAR itself. After talking to the manufacturer’s support, I was advised that the Plus Kiosk requires the startup-runtime-1.1.0 library (Startup Runtime initializes objects and components automatically when the application starts). I checked the manifest.xml inside the AAR and found the following declaration: <application> <provider android:name="androidx.startup.InitializationProvider" android:authorities="${applicationId}.androidx-startup" android:exported="false" tools:node="merge" > <meta-data android:name="com.e1.Comunicacao.ConUSB" android:value="androidx.startup" /> <meta-data android:name="com.e1.Pagamento.Brigde.ConfigFileInitializer" android:value="androidx.startup" /> </provider> </application> This explains the "null object reference" error, as the UsbManager class is not being initialized properly. However, as far as I understand, Delphi already includes this library internally. So I am looking for suggestions on how I can try to solve this issue: Is there a way to check if startup-runtime is correctly interacting with the manufacturer's libraries? Do I need to regenerate the JNI interface, adding startup-runtime to it? (I’m going to try this now, but I don’t see much sense in doing so.) Can someone please help me? I've already spent several days trying to understand and fix this error. -
In my understanding, FASMM shouldn't cause an increase of 20mb either, but that's the best guess because when I remove the FASMM call from the .dpr of my project the situation stops happening. i attached the memory leak report AutoatendimentoRefatorado_MemoryManager_EventLog.zip
-
oh the irony, the lib used to find memory leaks is causing memory leaks
-
you helped me a lot bro, i created another project and realise the problem wasn't happening then, after some search i realise that it was because FASTMM4 is active on the project
-
oh I forgot to mention that it's an FMX project I don't know if the same happens with VCL
-
i'm also using delphi 12.2 did you use the same json file? notice that the memory goes up 20mb after parsing?