I developed a application . Its working very nice at my phone but its not working when this application start to workin at the other phones
Its closed after the showing splash screen.
I taking this problem ,'EBitmapLoadinFailed' 'Loading Bitmap Failed' when i debug at the phone of the using with the other phones.
I have a bitmap in to listbox in my mainform.
I disabled bitmaps in listbox its woking
my form create code is,
procedure Tfrm_login.FormCreate(Sender: TObject);
var
strdb : String;
begin
try
strDB :=System.IOUtils.TPath.GetDocumentsPath + PathDelim + 'user.s3db';
with con do
begin
LoginPrompt := False;
Params.Clear;
Params.Values['Database'] := strDB;
Params.Values['DriverID'] := 'SQLite';
Params.Values['CharacterSet'] := 'utf8';
Connected := True;
end;
sqlexe('CREATE TABLE IF NOT EXISTS AYARLAMA('+
'ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,'+
'TIP NVARCHAR(50) NULL,'+
'DEGER NVARCHAR(255) NULL)');
except
//fdf
end;
end;
My Form Show Code,
procedure Tfrm_login.FormShow(Sender: TObject);
begin
try
with myq do
begin
sql.Clear;
sql.Add('SELECT * FROM AYARLAMA WHERE TIP='+''''+'MAIL'+'''');
Open;
if RecordCount>0 then
begin
first;
edit_ad.Text:=FieldByName('DEGER').AsString;
end;
end;
except
/// tyrt
end;
end;
I think installing Delphi's Android 5.0 update will help if the device is Android 5.0. I have solved my same problem that way.
The link is :
http://cc.embarcadero.com/item/30110
Related
First of all, I know a little bit about restarting an app. but that's when it is for windows. In this case, I need to make this for an app that is from android. I couldn't find a solution for it that works in Delphi. Just found this from #Mihai Limbășan I quote:
Perhaps you should think outside the box. Instead of futzing with the
mutex/instance logic, you could simply create another executable that
waits for your app to close then starts it again. As an added bonus,
you can later use this mechanism to, for example, update some of your
main app's binaries. It's also much easier to run it elevated instead
of maintaining different integrity levels inside the same app, etc.
But have no idea how this works or even where to start...
Every tip, code sample, or maybe other solution to restart an app will be appreciated.
EDIT
after some questions here are some pieces of code from the procedure.
First.
after you choose for example the language 'English and push the button save this happens
Inifile := TIniFile.Create(fPath);
try
Inifile.WriteString('Instelling','ip',edit5.text);
Inifile.WriteString('Instelling','user',edit6.text);
Inifile.WriteString('Instelling','pixels',edit3.text);
Inifile.WriteInteger('Instelling','language',Combobox2.ItemIndex);
fGebruiker := Edit6.Text;
fFotoformaat := StrToInt(edit3.Text);
finally
FDConnection1.Params.Values['server']:=edit5.Text;
FDConnection1.Connected := True;
inifile.free;
End;
with this code, I fill an inifile with data as you see also the item index of the Combobox for the language.
on this point i restart the app manually so the right language is chosen by this code:
procedure TfmMain.FormShow(Sender: TObject);
VAR
param : string;
inifile : tInifile;
begin
if (System.SysUtils.fileexists(fPath)) then
Begin
begin
Inifile := TIniFile.Create(fPath);
try
if not (Inifile.ReadString('Instelling','ip','default')='default') and not (Inifile.ReadString('Instelling','Gebruiker','default')='default')then
try
edit5.text := Inifile.ReadString('Instelling','ip','default');
edit6.text := Inifile.ReadString('Instelling','user','default');
Edit3.text := Inifile.ReadString('Instelling','pixel','400');
combobox2.ItemIndex := IniFile.ReadInteger('Instelling','language',1);
fpixel:= StrToInt(edit3.Text);
fuser:=edit6.text;
FDConnection1.Params.Values['server']:=edit5.Text;
taal := 'NL';
//find language settings
if combobox2.ItemIndex=0 then
begin
language:= 'NL'
end;
if combobox2.ItemIndex=1 then
begin
language:= 'ENG';
end;
if language='ENG' then
begin
vertalerENG.vertaler('ENG');
end;
end;
end;
end;
end;
the VertalerENG is a function that is fired if the language parameter is ENG and change all of the captions to English.
the problem is that nothing is changed till i restart the app.
If you want restart app programmatically,
This code work fine for me and you can set time elapse before restart app
uses
Androidapi.Helpers,Androidapi.JNI.GraphicsContentViewText,Androidapi.JNI.App,
System.DateUtils;
...
procedure RestartApp;
{$IFDEF ANDROID}
var LPM : JPackageManager;
LIntent_Start : JIntent;
LPendingIntent : JPendingIntent;
LMS : Int64;
{$ENDIF}
begin
{$IFDEF ANDROID}
LPM := TAndroidHelper.Context.getPackageManager();
LIntent_Start := LPM.getLaunchIntentForPackage(
TAndroidHelper.Context.getPackageName()
);
LIntent_Start.addFlags( TJIntent.JavaClass.FLAG_ACTIVITY_CLEAR_TOP );
LPendingIntent := TJPendingIntent.JavaClass.getActivity(
TAndroidHelper.Context,
223344 {RequestCode},
LIntent_Start,
TJPendingIntent.JavaClass.FLAG_CANCEL_CURRENT
);
LMS := DateTimeToUnix( Now, False {InputIsUTC} ) * 1000;
TAndroidHelper.AlarmManager.&set(
TJAlarmManager.JavaClass.RTC,
LMS + 10000,
LPendingIntent
);
// TAndroidHelper.Activity.finish();
Application.Terminate;
{$ENDIF }
end;
If changing the language is your only concern then i would suggest changing the locale of the application. You only need to restart the activity if you're using all the strings correctly from strings.xml
You can see it here how to change the locale of application programatically.
Change app language programmatically in Android
If this has already been visited here on SO, please point me to it, cause I cant seem to find it. Having said that:
Using the standard delphi application events, as well as the Mobile app lifecycle events handling , i am trying to find the best spot to read and write a INI file?
as I test, i created a demo app with a button which increments a count variable and displays it in a show message
procedure TfrmMain.Button1Click(Sender: TObject);
begin
inc(Count);
ShowMessage(IntToStr(Count));
end;
In the main form's OnCreate even, I read the inifile
procedure TfrmMain.FormCreate(Sender: TObject);
var
Ini: TIniFile;
begin
Ini := TIniFile.Create( TPath.GetDocumentsPath + PathDelim + 'fortysixtozero.ini' );
try
Count := Ini.ReadInteger( 'Main', 'Count', 0 );
finally
Ini.Free;
end;
end;
Now, knowing that a mobile app can have different states, i am wondering where the best place is to write the ini file?
Best states to save the application state or store settings is "aeEnteredBackground". I used the delphi FMX event here. You should also check the "aeWillBecomeInactive" and "aeWillTerminate" events, but the first one is the most relavant. The application enters background when another application is opened or yours is closed (they are not terminated right away).
Check this article.
The code to listen for events looks like this:
function TfMain.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
begin
case AAppEvent of
aeFinishedLaunching: ;
aeBecameActive: ;
aeWillBecomeInactive: ;
aeEnteredBackground: ;
aeWillBecomeForeground: ;
aeWillTerminate: ;
aeLowMemory: ;
aeTimeChange: ;
aeOpenURL: ;
end;
Result := True;
end;
To attach the listener you use the platform services:
if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(SvcEvents)) then
SvcEvents.SetApplicationEventHandler(HandleAppEvent);
Just add "FMX.Platform" to your uses clause.
In Delphi XE7, there is an "OnSaveState" event for forms. This is the preferred place to save application data since it will execute when an iOS app goes into the "background" state. The documentation is quite helpful... search for "save state".
Here is my code in the main form's OnCreate handler:
procedure TMainWindow.FormCreate( Sender : TObject );
var
IniFile : TIniFile;
Metric : BOOLEAN;
IniFileName : STRING;
Reader : TBinaryReader;
begin
fInitializing := True;
SaveState.StoragePath := TPath.GetLibraryPath;
if SaveState.Stream.Size > 0 then begin
Reader := TBinaryReader.Create( SaveState.Stream );
try
Metric := Reader.ReadBoolean;
vMetricUnits.IsChecked := Metric;
SetSliderLimits( Metric );
Temperature := Reader.ReadDouble;
Dewpoint := Reader.ReadDouble;
Humidity := Reader.ReadDouble;
WindSpeed := Reader.ReadDouble;
finally
Reader.Free;
end;
end
else begin
Metric := False;
vMetricUnits.IsChecked := Metric;
SetSliderLimits( Metric );
Temperature := 70;
Dewpoint := 70;
Humidity := 100;
WindSpeed := 0;
end;
SetMetricUnits( cMetricUnits );
fInitializing := False;
WriteTrackbarCaptions;
CalculateTemperatures;
end;
And here is the code in the form's OnSaveState handler:
procedure TMainWindow.FormSaveState( Sender : TObject );
var
Writer : TBinaryWriter;
begin
SaveState.Stream.Clear;
Writer := TBinaryWriter.Create( SaveState.Stream );
try
Writer.Write( cMetricUnits );
Writer.Write( Temperature );
Writer.Write( Dewpoint );
Writer.Write( Humidity );
Writer.Write( WindSpeed );
finally
Writer.Free;
end;
end;
I've tested this on both the iPad and in Windows and it works on both platforms. Doing it this way completely avoids the use of the .ini file, however it does create a somewhat oddly named .tmp file in the Windows version. I assume that an equivalent file is also created on the iPad.
I followed this tutorial step by step Mobile Tutorial: Using SQLite (iOS and Android) but when I deploy my application on my android device and attempt to add an entry, I get the following error "unable to open database file"
Here is a snippet of my code:
procedure TForm1.rappadAfterConnect(Sender: TObject);
begin
rappad.ExecuteDirect('CREATE TABLE IF NOT EXISTS notes(ID INTEGER PRIMARY KEY, title TEXT NOT NULL, content TEXT NOT NULL);');
end;
procedure TForm1.rappadBeforeDisconnect(Sender: TObject);
begin
{$IF DEFINED(iOS) or DEFINED(ANDROID)}
rappad.Params.Values['ColumnMetadataSupported'] := 'False';
rappad.Params.Values['Database'] :=
TPath.Combine(TPath.GetDocumentsPath, 'rappad.s3db');
{$ENDIF}
end;
Does anyone know why is this actually happening? Thanks!
The code you have in your rappadBeforeDisconnect needs to be in BeforeConnect instead. There's no point in telling the connection where the database is located before you disconnect.
procedure TForm1.rappadBeforeConnect(Sender: TObject);
begin
{$IF DEFINED(iOS) or DEFINED(ANDROID)}
rappad.Params.Values['ColumnMetadataSupported'] := 'False';
rappad.Params.Values['Database'] :=
TPath.Combine(TPath.GetDocumentsPath, 'rappad.s3db');
{$ENDIF}
end;
I am building an application for Android using Delphi XE5 that makes use of the Zxing barcode application and it uses the clipboard to retrieve the result. All of the code (Most of it anyway) is from a tutorial that I have found on the web. When I followed the tutorial, it worked to a charm but when applying the SAME code within an application that I was already working on - it did not work. Whenever accessing the clipboard ( in the 'OnTimer' event), the application always hangs and stops working. No error, nothing. App freezes and I have to close it via the phone's task manager.
The application fails right after the following line
Log.Add('AndroidClipboardScanner:1'); Log.SaveToFile(INIFileLog);
I have changed the coding around so that the app assumed the Clipboard service was available in the Ontimer event and it proceeded but it then failed after the following line:
Log.Add('AndroidClipboardScanner:4'); Log.SaveToFile(INIFileLog);
I am not sure where to begin debugging because the same code works in the other application that I created following the initial guide I found. I can also confirm that the ClipService is being assigned properly, otherwise the intent wouldn't even begin. Any help or guidance would be much appreciated ! Below is my code...
This Declared in the 'Private' variables section of the form:
ClipService: IFMXClipboardService;
This within the 'OnTimer' event for Timer1:
procedure TMain_Form.Timer1Timer(Sender: TObject);
var
barCode : String;
begin
timer1.Enabled := false;
Log.Add('AndroidClipboardScanner:0.1'); Log.SaveToFile(INIFileLog);
Try
if assigned(ClipService) then begin
Log.Add('AndroidClipboardScanner:1'); Log.SaveToFile(INIFileLog);
if (ClipService.GetClipboard.ToString <> 'nil') then
begin
Log.Add('AndroidClipboardScanner:2'); Log.SaveToFile(INIFileLog);
timer1.Enabled := false;
Log.Add('AndroidClipboardScanner:3'); Log.SaveToFile(INIFileLog);
Elapsed := 0;
Log.Add('AndroidClipboardScanner:4'); Log.SaveToFile(INIFileLog);
editHold.PasteFromClipboard;
//EditHold.Text := ClipService.GetClipboard.ToString;
Log.Add('AndroidClipboardScanner:5'); Log.SaveToFile(INIFileLog);
end else
begin
Log.Add('AndroidClipboardScanner:6'); Log.SaveToFile(INIFileLog);
Timer1.Enabled := False;
Log.Add('AndroidClipboardScanner:7'); Log.SaveToFile(INIFileLog);
end;
Log.Add('AndroidClipboardScanner:8'); Log.SaveToFile(INIFileLog);
end else begin
ShowMessage('Unexpected error has occured');
end;
Except
ShowMessage('Unexpected error has occured..');
End;
end;
Within the ONCreate procedure of the form:
if not TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService,
IInterface(ClipService)) then begin
ShowMessage('Clipboard Failed:1');
ClipService := nil;
end;
Elapsed := 0;
This is for click event for the button that begins the intent:
procedure TMain_Form.Button_ShowScannerClick(Sender: TObject);
{$IFDEF ANDROID}
var
intent: JIntent; {$ENDIF}
begin
{$IFDEF ANDROID}
//ShowMessage('Scanner:1');
if assigned(ClipService) then begin
//ShowMessage('Scanner:2');
ClipService.SetClipboard('nil');
intent := tjintent.Create;
intent.setAction(stringtojstring('com.google.zxing.client.android.SCAN'));
intent.putExtra(tjintent.JavaClass.EXTRA_INTENT,
stringtojstring('"SCAN_MODE"'));
sharedactivity.startActivityForResult(intent,0);
Elapsed := 0;
timer1.Enabled := true;
//ShowMessage('Scanner:3');
end;
{$ENDIF}
You didn't set the SCAN_MODE parameters like:
intent.putExtra(tjintent.JavaClass.EXTRA_TEXT,
stringtojstring('"SCAN_MODE","ONE_D_MODE,QR_CODE_MODE,PRODUCT_MODE,DATA_MATRIX_MODE"'));
Also you can check timer interval parameter...
I tested the solution on few devices.
With low interval value I had black screen sometimes
Has anyone been able to take pictures from camera on Android from within the app written in Delphi Firemonkey XE5? How about the video capture?
This is believed to be either a bug in a framework or just something with missing documentation about it.
Can anyone tell why the code bellow doesn't work / retrieve any image from a camera on Android?
Dropped a TCameraComponent on a form, and a TImage component as well, and nothing happens.
procedure TCameraComponentForm.OnCreate(Sender: TObject);
begin
CameraComponent1.Kind := FMX.Media.TCameraKind.ckFrontCamera;
CameraComponent1.FlashMode := FMX.Media.TFlashMode.fmFlashOff;
CameraComponent1.Active := True;
end;
procedure TCameraComponentForm.CameraComponent1SampleBufferReady(
Sender: TObject; const ATime: Int64);
begin
CameraComponent1.SampleBufferToBitmap(Image1.Bitmap, True);
Image1.Width := Image1.Bitmap.Width;
Image1.Height := Image1.Bitmap.Height;
end;
Permissions are set correctly.
This code works fine:
procedure TfrmPrincipal.SampleBufferSync;
begin
cmcPrincipal.SampleBufferToBitmap(imgFoto.Bitmap, true);
end;
procedure TfrmPrincipal.cmcPrincipalSampleBufferReady(Sender: TObject;
const ATime: Int64);
begin
TThread.Synchronize(TThread.CurrentThread, SampleBufferSync);
// CameraComponent1.SampleBufferToBitmap(imgFoto.Bitmap, True);
// imgFoto.Width := imgFoto.Bitmap.Width;
// imgFoto.Height := imgFoto.Bitmap.Height;
end;
procedure TfrmPrincipal.FormShow(Sender: TObject);
begin
cmcPrincipal.Kind := FMX.Media.TCameraKind.ckBackCamera;
try
cmcPrincipal.FlashMode := FMX.Media.TFlashMode.fmFlashOff;
except
end;
cmcPrincipal.Active := True;
end;