Link to home
Start Free TrialLog in
Avatar of Member_2_7965240
Member_2_7965240

asked on

Android App: how to choose the installation folder?

Hello,

I wrote an Android App in Delphi.

I noticed the some applications are installed directly under root directory e.g. /sdcard/AnkiDroid or /sdcard/doubleTwist.
However my app is installed somewhere else (I think /sdcard/Android/data).

How can I change it? Or if I can't how can I make the installation make a folder in the root directory?
I need the user to copy a file there so as my app would parse it.

Thank you very much!
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

I think that there is no way to install anywhere but /sdcard/Android/data. Even this apps (doubleTwist? ..) are locate there but use folders as you noticed to keep some data....
And why you need separate folder for your app?
Avatar of Member_2_7965240
Member_2_7965240

ASKER

I need the users to copy files in that directory so as my app would parse it.
Most users don't have much experience in copying files so I want to make things easier for them (not to find a directory which is hidden at first sight).
Then create folder from your app and look for it when need it... Let folder be empty (without installation files) and user will not be able to delete your essential app/data/files.
How can I create a folder from my app? If I know well, Android doesn't allow it or am I wrong?

Thank you.
1. you can extract root part out of TPath.GetSharedMusicPath and concatenate your folder or
2. use very useful functions collections from here  or here and make something like this:
uses System.IOUtils, FlyFilesUtils;
...
var
  sSDCard: String;
begin
  sSDCard := GetExternalStoragePath;  //GetSDCardPath;
  ForceDirectories(TPath.Combine(sSDCard, 'MyAppFolder'));
end;

Open in new window

Hello,
Sorry for the late reply.

I tested your code but at compile I get [DCC Fatal Error] FlyFilesUtils.pas(360): F2613 Unit 'Androidapi.JNI.Environment' not found.
I use Delphi Seattle.

it stops here:

uses
{$IFDEF ANDROID}
{$IF CompilerVersion >= 27.0} // >= XE6
  Androidapi.Helpers,
//  FMX.Helpers.Android,
{$ENDIF}
{$IF CompilerVersion < 28.0} // < XE7
  FMX.Helpers.Android,
{$ENDIF}
  Androidapi.Jni,
  Androidapi.JNI.Environment,
  Androidapi.JNI.StatFs,
  Androidapi.JNI.Stream2,
  Androidapi.JNI.ActivityManager,

Thank you very much.
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
One more problem
I got this error message:
[DCC Error] FlyFilesUtils.pas(531): E2003 Undeclared identifier: 'EncodePath'

This is the code snippet. Obviously Delphi Seattle doesn't contain EncodePath, But what should I change it to?

{$IF CompilerVersion >= 29.0} //  XE8
   AURL := URL.Trim;
   Protocol := '';
   AIndex := AURL.IndexOf('//');
   if AIndex > 0 then
   begin
     Protocol := AURL.Substring(0, AIndex + 1); // has /
     AURL := AURL.Substring(AIndex + 1); // has /
   end;
   Result := Protocol + TNetEncoding.URL.EncodePath(AURL);  
{$ELSE}
   Result := TIdURI.URLEncode(Result);
{$ENDIF}

Thank you.
Sorry, don't have Seattle to test, but here is what you can:
- use some text find tool (wincommander, ransec,...) and look for .pas files in Embarcadero (xe10) install folder for text EncodePath
- it is possible that function exists in different unit other than System.NetEncoding
- change it in uses if you find it ....

-if all fails... then change few lines from:
...
{$IF CompilerVersion >= 29.0}
...

Open in new window

to
...
{$IF CompilerVersion >= 31.0}
...

Open in new window

and this way you will use replacement (old) function ...