0% found this document useful (0 votes)
259 views3 pages

How To Load A File Into A Stream On Android Knowing Its Jnet - Uri - Stack Overflow

The question asks how to load a file into a stream in an Android FMX app using Delphi, given the file's URI. The URI is obtained from selecting a photo from the gallery. Simply converting the URI to a path does not work, as the path is invalid for loading from. The answer provides a solution to use a JInputStream to read the data from the URI and load it into a TMemoryStream for further processing.

Uploaded by

Daniel Rodriguez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
259 views3 pages

How To Load A File Into A Stream On Android Knowing Its Jnet - Uri - Stack Overflow

The question asks how to load a file into a stream in an Android FMX app using Delphi, given the file's URI. The URI is obtained from selecting a photo from the gallery. Simply converting the URI to a path does not work, as the path is invalid for loading from. The answer provides a solution to use a JInputStream to read the data from the URI and load it into a TMemoryStream for further processing.

Uploaded by

Daniel Rodriguez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Stack Overflow Sign up Log in

Questions Jobs Tags Users Badges Ask

4 How to load a file into a stream on Android knowing its Jnet_Uri?


android
delphi
uri
firemonkey
delphi-10.3-rio

I'm writing an Android FMX app in Delphi 10.3 Rio. There I'm selecting photos from the gallery (via
TJIntent.JavaClass.ACTION_OPEN_DOCUMENT ) and getting back Jnet_Uri entries. I can use those to read
image EXIF (with TJExifInterface). Now I also need to load these images into a stream for further
processing. How do I do this?

When I try to convert Jnet_Uri to a path with uri.getPath , it comes out like /document/image:26591 .
uri.toString gives me
content://com.android.providers.media.documents/document/image%3A26674 .
TMemoryStream.LoadFromFile fails to load from both of these paths:

Cannot open file "/document/image:26724". No such file or directory

Cannot open file "/content:/com.android.providers.media.documents/document/image%3A26724".


Not a directory

Hence the question, how knowing a Jnet_Uri do I load files contents into a stream?

Share
Improve this question
Follow

Kromster
asked
6,675 ● 7 ● 55 ● 99 Mar 11 '19 at 5:31

edited
Mar 11 '19 at 7:11

Same question in Rus: ru.stackoverflow.com/questions/954877


–  Kromster
Mar 11 '19 at 6:00

Add a comment

1 Answer order by
votes

I was able to read the data via JInputStream:


4

var

uri: Jnet_Uri;

ms: TMemoryStream;

jis: JInputStream;

b: TJavaArray<Byte>;

begin
uri := .. some uri, alike "/document/image:26591"

ms := TMemoryStream.Create;

// Need to read via JInputStream, since Uri is not a file

jis := TAndroidHelper.Context.getContentResolver.openInputStream(uri);

b := TJavaArray<Byte>.Create(jis.available);

jis.read(b);

ms.Write(b.Data^, b.Length);

jis.close;

Share
Improve this answer
Follow

Kromster
answered
6,675 ● 7 ● 55 ● 99 Mar 11 '19 at 7:43

Can you post the whole code, please? I have the same issue as you did, thanks
– Dejan Dozet
Feb 11 '20 at 9:10

@dedo ms is a typical stream that can be used in common Delphi way. What gives you problems?
–  Kromster
Feb 11 '20
at 9:14

Here is my post: stackoverflow.com/questions/60155948/…


– Dejan Dozet
Feb 11 '20 at 9:27

Add a comment

Your Answer

Body


Add picture

Log in

OR

Name

Email
By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Post Your Answer

meta
chat
tour
help
blog
privacy policy
legal
contact us
cookie settings
full site
2021 Stack Exchange, Inc. user contributions under cc by-sa

You might also like