Lazarus

Programming => Operating Systems => Android => Topic started by: Mongkey on May 18, 2021, 08:11:42 am

Title: LAMW - open existing file into a filestream (fmopenread - solved, android 10)
Post by: Mongkey on May 18, 2021, 08:11:42 am
Is there any method for opening exsisting file into stream format?

->Permission
->Newstream:=TFilestream.create('existing file a',fmopenread);
->error
Title: Re: LAMW - open existing file into a filestream (fmopenread - failed, android 10)
Post by: loaded on May 18, 2021, 08:56:30 am
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.  
Title: Re: LAMW - open existing file into a filestream (fmopenread - failed, android 10)
Post by: Mongkey on May 18, 2021, 10:55:09 am
I wrote same script like yours -> failed   :D, may be need more coffee to find the solution.

Have you try on android 10?
Title: Re: LAMW - open existing file into a filestream (fmopenread - failed, android 10)
Post by: loaded on May 18, 2021, 06:39:40 pm
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" ...... >
Title: Re: LAMW - open existing file into a filestream (fmopenread - failed, android 10)
Post by: jmpessoa on May 18, 2021, 07:52:37 pm
@loaded

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

Nice!

I will update/fix LAMW manifest template!

Thank you!
Title: Re: LAMW - open existing file into a filestream (fmopenread - failed, android 10)
Post by: Mongkey on May 19, 2021, 04:36:22 am
 :), 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.
Title: Re: LAMW - open existing file into a filestream (fmopenread - solved, android 10)
Post by: jmpessoa on May 19, 2021, 06:07:51 pm
Quote
i was also updated xml support provider ...

What LAMW file you changed?
Title: Re: LAMW - open existing file into a filestream (fmopenread - solved, android 10)
Post by: Mongkey on May 20, 2021, 01:41:38 am
Res -> xml -> file provider setting

This setting has deal with camera  or file access i not mistaken   :)
TinyPortal © 2005-2018