Android Test App perform programming steps backwards - android

I am using Delphi Enterprise version 10.2.3 with Android SDK ver 24.3.3 32bit. I tried a very simple program with only one button. The Onclick is simply the following:
ShowMessage('1');
ShowMessage('2');
ShowMessage('3');
ShowMessage('4');
The result I got on my Samsung phone when clicking on the button is:
4
3
2
1
Of course I am expecting to get
1
2
3
4
This is not my first Android Program. The previous ones runs smoothly. But when I got strange errors on my latest program, I found that programming steps are carried out in reverse. I am also scared now to recompile the previous apps, just in case I am getting this strange behavior. So I just make a new program (above) to test, but got the same results. I also disabled the Antivirus Avast program, and even try it on another Samsung device.
Help will be very much appreciated. At this moment I am really confused and not sure what next steps to take to solve the problem. Please help me!

On mobile platforms, ShowMessage behaves asynchronously. The call finishes instantaneously, it does not wait for the user to close the dialog box.
Try this code:
function TForm1.MyShowMessage(const Msg: String): TModalResult;
var
MR: TModalResult;
begin
MR := mrNone;
TDialogService.MessageDialog(Msg, TMsgDlgType.mtConfirmation,const [TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo], TMsgDlgBtn.mbYes, 0,
procedure(const AResult: TModalResult)
begin
 MR := AResult;
end);
while MR = mrNone do begin
Application.ProcessMessages;
CheckSynchronize;
end;
Result := MR;
end;

Related

Delphi 10.3.1 - Android Service hangs on System.InitUnits

I've created simple Android Service on 10.2.3 and pinned it to my Android App same as it stands in docs. However, there where no libProxyAndroidService.so in {$BDS}/lib/android/release, I've copied it from debug dir. Next thorn made by Embarcadero to me was hanging of whole application while calling
TLocalServiceConnection.StartService('somename');
I have installed 10.3.1 with hope that this bug is eliminated in this release, but it did the same.
Running app in debug mode, I have putted some breakpoints in System.Android.ServiceApplication, when steping over and over by code, it crashed in System.InitUnits, line 23357:
try
while I < Count do
begin
P := Table^[I].Init;
Inc(I);
InitContext.InitCount := I;
if Assigned(P) and Assigned(Pointer(P^)) then
begin
{$IF defined(MSWINDOWS)}
TProc(P)();
{$ELSEIF (defined(POSIX) and defined(CPUX86)) and defined(ASSEMBLER)}
CallProc(P, InitContext.Module^.GOT);
{$ELSE}
TProc(P)(); << 23357 crashing
{$ENDIF}
end;
After execution of malfunctional P, UI thread hangs out, Service is never executed, but in background Android App is still executing code (new threads in message log)
Edit:
I've checked what is under P^
This is initalization part of unit FMX.Platform
https://quality.embarcadero.com/browse/RSP-17857
It's old bug, never fixed by Embarcadero
Just remove all things which use FMX.Types unit, remove this unit from evey uses.
Then set ClassGroup to TPersistent
Wasted hours :|
procedure TPlatformAndroid.BindAppGlueEvents;
var
AndroidAppGlue: TAndroidApplicationGlue;
begin
AndroidAppGlue := PANativeActivity(System.DelphiActivity)^.instance; // <------- Error occurs here
AndroidAppGlue.OnApplicationCommandEvent := HandleApplicationCommandEvent;
AndroidAppGlue.OnContentRectEvent := HandleContentRectChanged;
AndroidAppGlue.OnInputEvent := HandleAndroidInputEvent;
end;
Related issues: RSP-12199 and RSP-13381. FMX seems to have a lot of problems related to use of System.DelphiActivity in a service. And for good reason. DelphiActivity probably shouldn't exist in the first place! You are not supposed to hold on to references to the Activity object in the first place. And a Service doesn't even require an Activity to run! Apps and Services alike run as Contexts instead (the Activity and Service classes both derive from the Context class), so if you need to hold a reference to something, hold one to the Context that the code is running in (which FMX also does). What is FMX doing with DelphiActivity that is so important that it can't be done in other (safer) ways?
Conclusion: There is nil in System.DelphiActivity in Services so loading FMX units will create a crash in initUnits.
PDFed link with bug explanation: https://www.docdroid.net/TfUjBwg/bug.pdf

Delphi android application is raising issue in Lennova A5000 mobile

I'm using Delphi 10 Seattle trail version for developing mobile application. And I tried to create new android mobile application which contains only TEditBox. And then compiled by setting the option as "Release". Then, generated the .apk file and then provided the file to the user. And when the user tried to click the edit box, the application raises the error message that "The Appname is not responding".
The user is using the Lennova A5000 and the Os is Android 5.0.2.
And the same application is running in my Moto g2 (5.0.2) and Micromax Yureka.
Please provide me is there any solution.
Also, I have updated the app in google app store. Then, it is showing as incompatible application for this device (Lennova A5000).
And also I have updated all the android SDK packages. After that also, it is raising the same issue.
I think this may be problem to Embarcadreo Delphi or any missing packages? Dont know what to do.
Thanks in advance.
Atlast I got the solution from Embarcadreo website. Please follow the mentioned steps.
1.Copy FMX.Platform.Android.pas to the project folder from source/fmx folder
and add the copied files to the project.
Then, do the changes in the following procedures.
procedure TPlatformAndroid.RunOnUIThread(Proc: TThreadProcedure);
procedure TPlatformAndroid.RunOnUIThread(Proc: TThreadProcedure);
begin
//MainActivity.runOnUiThread(TSimpleProcedureRunner.Create(Proc));
CallInUIThread(
procedure()
begin
Proc;
end);
end;
procedure TPlatformAndroid.SynchronizeOnUIThread(Proc: TThreadProcedure);
procedure TPlatformAndroid.SynchronizeOnUIThread(Proc: TThreadProcedure);
var
Runner: TSimpleProcedureRunner;
begin
// CallInUIThread(
// procedure()
// begin
// Runner := TSimpleProcedureRunner.Create(Proc);
// MainActivity.runOnUiThread(Runner);
// Runner.Event.WaitFor;
// end);
CallInUIThreadAndWaitFinishing(
procedure()
begin
Proc;
end);
end;
procedure TPlatformAndroid.SetClipboard(Value: TValue);
procedure TPlatformAndroid.SetClipboard(Value: TValue);
var
Setter: TClipboardSetter;
begin
Setter := TClipboardSetter.Create(Value.ToString);
CallInUIThread(
procedure()
begin
SharedActivity.runOnUiThread(Setter);
end);
Setter.Done.WaitFor(INFINITE);
end;
function TPlatformAndroid.GetClipboard: TValue;
function TPlatformAndroid.GetClipboard: TValue;
var
Getter: TClipboardGetter;
begin
Getter := TClipboardGetter.Create;
CallInUIThread(
procedure()
begin
SharedActivity.runOnUiThread(Getter);
end);
Getter.Done.WaitFor(INFINITE);
Result := Getter.Value;
end;
Then, Rebuild the project. After doing this every thing is working fine.

Barcode reading Delphi xe7, event after intent not triggering

In my app, developed with XE7 for Android/iOS, I have a form for scanning barcodes. Upon a found barcode, my app validates whether it is an acceptable barcode or not. Following tutorials here: http://www.fmxexpress.com/qr-code-scanner-source-code-for-delphi-xe5-firemonkey-on-android-and-ios/
Currently I am testing on Android and I am able to integrate scanning and reading of barcodes, but the 'onBarCode' event does not fire when returned from the shared Activity of finding the barcode. Same code worked well with previous versions of Rad Studio ( XE4, XE5, XE6) but now in XE7 it does not.
Here are some snippets of code:
...
begin
Scanner := TAndroidBarcodeScanner.Create(true);
Scanner.OnBarCode := BarcodeHandler;
Scanner.Scan;
end;
procedure TmScannerForm.BarcodeHandler(Sender: TAndroidBarcodeScanner;
BarCode: String);
begin
text1.Text := Barcode;
memo1.PasteFromClipboard;
AddBarcode(BarCode, true);
end;
AddBarCode is the even I used to validate and add barcode to a list, but I didnt include it, because that code isn't the problem - it's not even triggering. The Text1.text:=Barcode and memo1.paseFromClipboard were in their for validating the even wasn't firing too. I can confirm the barcodes are being read because if I tap and manually paste, the barcode shows.
Why is this not working on XE7 as it did in previous versions of Rad Studio?
Andrea Magni has a more elegant solution than the timer on his blog based on event handling.
I would comment to send the link but I don't have enough reputation.
The link to his blog is :
http://blog.delphiedintorni.it/2014/10/leggere-e-produrre-barcode-con-delphi.html
Maybe this can help you. The blog is in Italian though but the sources are provided and are explaining by themselves.
There is a source code fragment on http://john.whitham.me.uk/xe5/ which looks useable (based on Zxing):
intent := tjintent.Create;
intent.setAction(stringtojstring('com.google.zxing.client.android.SCAN'));
sharedactivity.startActivityForResult(intent,0);
The code in the linked article also shows how to receive the Intent result. (I don't work with Delphi on Android so I am not sure if that part uses a best practice - TTKRBarCodeScanner uses a workaround with a Timer and the Clipboard).
I would try this as an alternative to see if works.
This code works to me!
Set timer enabled to true when you run your scan code
procedure Tform.Timer1Timer(Sender: TObject);
begin
if (ClipService.GetClipboard.ToString <> '') then
begin
timer1.Enabled:=false;
zSearch.Text := ClipService.GetClipboard.ToString;
//Do what you need
end;
end;
This code to me works fine!
in andorid.BarcodeScanner
function TAndroidBarcodeScanner.HandleAppEvent(AAppEvent: TApplicationEvent;
AContext: TObject): Boolean;
var
aeBecameActive : TApplicationEvent;
begin
aeBecameActive := TApplicationEvent.BecameActive;
if FMonitorClipboard and (AAppEvent = aeBecameActive) then
begin
GetBarcodeValue;
end;
end;

Empty product list on QueryProducts in Delphi XE6 TInappPurchase on Android

I am developing inapp-Purchase in Delphi XE6.
Based on embarcadero documentation I create an InAppPurchase component as below:
FInAppPurchase := TInAppPurchase.Create(self);
{$IFDEF Android}
FInAppPurchase.ProductIDs.Add(License5And);
FInAppPurchase.ProductIDs.Add(License10And);
FInAppPurchase.ProductIDs.Add(License20And);
FInAppPurchase.ProductIDs.Add(License50And);
{$ENDIF}
{$IFDEF IOS}
FInAppPurchase.ProductIDs.Add(License5);
FInAppPurchase.ProductIDs.Add(License10);
FInAppPurchase.ProductIDs.Add(License20);
FInAppPurchase.ProductIDs.Add(License50);
{$ENDIF}
FInAppPurchase.OnSetupComplete := InAppPurchase1OnSetupComplete;
FInAppPurchase.OnConsumeCompleted := InAppPurchase1ConsumeCompleted;
FInAppPurchase.OnError := InAppPurchase1Error;
FInAppPurchase.OnProductsRequestResponse := InAppPurchase1ProductsRequestResponse;
FInAppPurchase.OnPurchaseCompleted := InAppPurchase1PurchaseCompleted;
FInAppPurchase.OnRecordTransaction := InAppPurchase1RecordTransaction;
FInAppPurchase.OnVerifyPayload := InAppPurchase1VerifyPayload;
{$IFDEF Android}
FInAppPurchase.ApplicationLicenseKey := myLicenseKeyFromGoogleDeveloperConsole;
{$ENDIF}
Then in InAppPurchase1OnSetupComplete I Called the FInAppPurchase.QueryProducts then it goes into InAppPurchase1ProductsRequestResponse and products and InavlidProductIDs both are empty. I don't know what I missed. Any help will be appreciated.
I check my products in google developer console all of them are 'Active' and as Type of 'Managed'.
p.s. Code is working perfect on ios Device.
I lost a lot of time to understand the problem.
After I studied the source code I have understand that in Android the Events are asynchronous, you must wait the "QueryProducts" result.
In order to fix this problem I created a TTimer that wait 5 second before it read "InAppPurchase.IsProductPurchased"
(I'm sorry for bad English)
It seems the app should be published for alpha or beta testing.
Instead of uploading for production I need to upload it for alpha first then publish it. after that the products are shown.
I developed the interface with the market starting from the example CapitalITrivia in Enbarcadero. I had the same problem and I read the answer that was given here.
I tried it and actually works. But this solution did not satisfy me because it depends on a delay not justified.
I realized that in InAppPurchaseSetupComplete was called the QueryProducts function and then I performed IsProductPurchased.
If I move the IsProductPurchased test in InAppPurchaseProductsRequestResponse function I get the expected result without introducing the delay.

Alarm Clock using DELPHI XE5 and Android

did someone already find the correct way to program an alarm clock using DEPHI XE 5 and Android OS?
I found this code , but it does not work/compile at all:
procedure TNotificationsForm.btnSendScheduledNotificationClick(Sender: TObject);
var
Notification: TNotification;
begin
{ verify if the service is actually supported }
if NotificationC.Supported then // compile error here
begin.Supported
Notification := NotificationC.CreateNotification; // compile error here
try
Notification.Name := 'MyNotification';
Notification.AlertBody := 'Delphi for Mobile is here!';
{ Fired in 10 second }
Notification.FireDate := Now + EncodeTime(0,0,10,0);
{ Send notification in Notification Center }
NotificationC.ScheduleNotification(Notification);
finally
Notification.DisposeOf;
end;
end
end;
The first error is that NotificationC.Supported this property does not exist
You should mention that the code is based on one of the sample applications distributed with XE5. They can be found in the Start Menu entry for XE5 under Samples, or in the default C:\Users\Public\Documents\RAD Studio\12.0\Samples\MobileCodeSnippets\Notifications folder (Windows 7).
It appears you've forgotten to drop the TNotificationCenter component (available on the Component Palette's Services page) on the form and name it NotificationC as the demos do. Once you've done that, your code compiles just fine.
When you mention that you get a "compile error" in a question here, it's important to include the error message. We can't see your screen from where we are. :-) You have that exact information right in front of you, so there's no excuse for not including it. The Messages window will even copy the exact message to the clipboard for you to paste here, if you right-click the error line.

Categories

Resources