Recent

Author Topic: LAMW - open existing file into a filestream (fmopenread - solved, android 10)  (Read 4424 times)

Mongkey

  • Jr. Member
  • **
  • Posts: 84
Is there any method for opening exsisting file into stream format?

->Permission
->Newstream:=TFilestream.create('existing file a',fmopenread);
->error
« Last Edit: May 19, 2021, 04:37:04 am by Mongkey »

loaded

  • Full Member
  • ***
  • Posts: 212
Is there any method for opening exsisting file into stream format?

LAMW is a blessing. Whatever you look for is there  :)

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.AndroidModule1JNIPrompt(Sender: TObject);
  2. begin
  3.  if IsRuntimePermissionGranted('android.permission.WRITE_EXTERNAL_STORAGE') = False then
  4.     Self.RequestRuntimePermission('android.permission.WRITE_EXTERNAL_STORAGE',1001);
  5. end;
  6.  
  7.  
  8. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  9. var
  10.   Stream:TFileStream;
  11.   StreamFilePath: string;
  12.  
  13. begin
  14.   if IsRuntimePermissionGranted('android.permission.WRITE_EXTERNAL_STORAGE') then
  15.   begin
  16.     StreamFilePath:= Self.GetEnvironmentDirectoryPath(dirDownloads)+'/'+'123.mp4';
  17.     Stream:=TFileStream.Create(StreamFilePath,fmOpenRead or  fmShareDenyNone);
  18.     // You can use TReadBufStream to read at higher speeds. Ex: Fastspeedstream:=TReadBufStream.Create(Stream);
  19.     ShowMessage(inttostr(Stream.Size));
  20.     Stream.Free;
  21.   end
  22.   else  Showmessage('Sorry.. "WRITE_EXTERNAL_STORAGE"  DENIED ...');
  23. end;
  24.  
Installing the spelling, google translate is used :)

Mongkey

  • Jr. Member
  • **
  • Posts: 84
I wrote same script like yours -> failed   :D, may be need more coffee to find the solution.

Have you try on android 10?

loaded

  • Full Member
  • ***
  • Posts: 212
I tried it on Android 8 and 11, it was working without any problems.
As you said yes, there were 10 problems, but when I added the following parameter to the manifest file, it worked without any problems.
Code: Pascal  [Select][+][-]
  1. <application ......  android:requestLegacyExternalStorage="true" ...... >
Installing the spelling, google translate is used :)

jmpessoa

  • Hero Member
  • *****
  • Posts: 1832
@loaded

Quote
but when I added the following parameter to the manifest file...

Nice!

I will update/fix LAMW manifest template!

Thank you!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Mongkey

  • Jr. Member
  • **
  • Posts: 84
 :), thanks, i forgot my apps was not ready for local sandboxing on android 10  :-X

i was also updated xml support provider path for android 10.

it was very useful on android 10, for creating custom media database on sdcard from direct shoot camera, existing image etc.
« Last Edit: May 19, 2021, 04:44:15 am by Mongkey »

jmpessoa

  • Hero Member
  • *****
  • Posts: 1832
Quote
i was also updated xml support provider ...

What LAMW file you changed?
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Mongkey

  • Jr. Member
  • **
  • Posts: 84
Res -> xml -> file provider setting

This setting has deal with camera  or file access i not mistaken   :)
« Last Edit: May 20, 2021, 01:46:52 am by Mongkey »

 

TinyPortal © 2005-2018