Jump to content
KMarb

Delphi Berlin FMX app runs on android 10 but not beyond

Recommended Posts

A few years ago I wrote 3 android apps for my company using Delphi Berlin. They've worked well enough for us, but more and more we're having trouble finding android devices that will work with these older apps. I've found I can run on as late as android 10 on some phones (Blackview bv5900), but not on any android 11 phones. My app uses basic permissions like network, location, camera, but it also writes to external storage (probably don't need to do that... just have an ini file so the 3 apps can share some info, written once and then only ever read when apps start up).

 

I'm looking for suggestions.

 

Is it possible I can change permissions or android SDK/NDK and continue to use Berlin to get these working for current android versions?

If I need to use a new version of Delphi, what would be best for android development?

And is there a document to walk me through changes from Berlin to the new version?

What SDK/NDK version should I use?

 

Once before (prior to Delphi 11) I tried recompiling my FMX apps on a new Delphi (10.4 I believe) and there were many error messages. It was a bit overwhelming since my mindset was I could simply recompile and have new apk's to distribute. So, I haven't invested a lot of time in to how to get my apps updated, but the urgency is greater now so I need to spend whatever time is needed.

 

Thanks in advance for any suggestions.

 

Oh, last thing - I read posts for 30 minutes on this site and was impressed by the level of knowledge. Looking forward to getting involved here.

 

Keith Marbach

Share this post


Link to post

If you're using the original project, follow the steps here to ensure that it has references to the correct Android libraries: https://github.com/DelphiWorlds/HowTo/tree/main/Solutions/AndroidLibraries

Delete the original AndroidManifest.template.xml, making sure you note any customizations you added yourself. Recompiling the project should recreate the AndroidManifest.template.xml file and you can add any customizations back in. I suspect the error messages you were seeing when you tried compiling with Delphi 10.4 may have been related to having an older AndroidManifest.template.xml.

 

Assuming that you had not changed the %targetSdkVersion% part of AndroidManifest.template.xml, you will find that your app will now need to request permissions for "dangerous" permissions at runtime, so you will need to modify your code to suit. There's examples of how to do this in demos like in the camera component demo: https://github.com/Embarcadero/RADStudio11Demos/tree/main/Object Pascal/Mobile Snippets/CameraComponent and the location demo: https://github.com/Embarcadero/RADStudio11Demos/tree/main/Object Pascal/Mobile Snippets/Location

 

If you opted to install the Android SDK/NDK files when you installed Delphi 11, when you add an SDK, it should default to the compatible values anyway.

 

Share this post


Link to post

Hi Keith,

 

Yes, it would be possible to make berlin target newer androids, looked into it myself, but in my opinion, it's not the correct path.

Upgrade to D11, follow steps above in Dave's response because I didn't at first, no fun.

 

and my in experience, there's usually something that is different that causes a bit of work, I don't typically expect a perfect compile first time on a new D version.

 

I will say this, I'm on Android 11 now. 🙂

 

Good Luck,

 

Dave

Share this post


Link to post

Wow! Thank you both so much!

 

I now have apk that i've been able to install on android 11, and it runs, but I get an error "cannot access local data" I'm assuming that's because i have not added code for permissions, which I will work on next. My app uses location, camera, and writes to storage. It also invokes a bar code scanner, I believe made by ZXing. I will look at the camera and location examples to learn.

 

The only reason I write/read from storage is because i have 3 apps, and I wanted a way to share info between the 3. When one gets registered with my server, the ini file is written with some information. The other 2 apps can then read that info. Info like device name (as registered in my back end database) and one or two other things. I'm showing my code below in case you think I should throw it away and try another approach:

 

    procedure checkIniFile;
    begin
      iniPath := ExtractFilePath (ExcludeTrailingPathDelimiter (TPath.GetSharedDownloadsPath));
      iniPath := TPath.Combine (iniPath, 'MyFolderName');
      ForceDirectories (iniPath);

 

      iniFileName := TPath.Combine(iniPath, 'MyFileName.ini');
      exportDBFileName := TPath.Combine (iniPath, DMConn.DBFileName);

      IniFileExists := FileExists (iniFileName);
    end;
 

I am indebted to you for your time already spent, but if something jumps out at you about my approach to access a shard ini file across multiple apps, I'd appreciate being set on a better path. Also if you have any warnings about access a bar code scanner. here is that code;

 

procedure TfrmMain.activateBarcodeScanner;
begin
  FMessageSubscriptionID := TMessageManager.DefaultManager.SubscribeToMessage
          (TMessageResultNotification, HandleActivityMessage);

  ignoreWillBecomeForeground := true;
  ignoreBecameActive := true;
  inBarCodeScanner := true;
  LaunchQRScanner (ScanRequestCode);
end;

 

function LaunchQRScanner;
var
  Intent: JIntent;
begin
  Intent := TJIntent.JavaClass.init(StringToJString('com.google.zxing.client.android.SCAN'));
  Intent.setPackage(StringToJString('com.google.zxing.client.android'));
  result := LaunchActivityForResult(Intent, RequestCode);
end;
 

I'm very rusty on android, and I learned by doing, nothing formal, so I might need to back up and learn or re-learn some basics.

 

Thanks again. You've given me a huge head start.

 

Keith

Share this post


Link to post

Hi Keith,

 

Using an ini file myself but in TPath.GetHomePath.

don't extract or exclude anything, TPath handles that.

iniPath:=TPath.Combine(TPath.GetSharedDownloadsPath, 'MyFolderName');

Then use TFile and TDirectory..

if not TDirectory.Exists(...) then TDirectory.CreateDirectory(...);

TFile also has an exists method.

 

and the ini:=TIniFile.Create(TPath.Combine(iniPath,'my.ini'));

 

Again, using home path, I need no permissions, using  shared path, might need them so check them.

 

can't comment on barcode, sorry..

 

Dave

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×