Android question...

Android question...

This might sound ridiculously simple to do but cross platform API isn't my strong point.

I started an Activity with the Intent of consuming content from the Gallery which works fine. However, the Intent returns the URI of the file (as content://storage/... /media/12345) instead of the actual file path.

I was expecting something like '/storage/emulated/0/.../VID_18161918.MP4'

Any pointers?

UPDATE ----
after going through the Android documentation and some examples (that probably work in Java). This is the code which I 'feel' should work.. but it is not... any help would be great


function TForm2.HandleIntentAction(const Data: JIntent): Boolean;
var
P: TJavaObjectArray;
C: JCursor;
I: Integer;

begin
Memo1.Lines.Text := JStringToString(Data.getData.toString); // this returns the URI in string perfectly... so I know that I am getting the file path properly


// this is to prepare the information I need... they call it projection
P := TJavaObjectArray.Create(2);
P.Items[1] := StringToJString('_ID');
P.Items[2] := StringToJString('DATA');

// this is suppose to give the information back to C ( : JCursor)
C := MainActivity.getContentResolver.query(Data.getData, P, nil, nil, nil);
C.moveToFirst;

I := 0;
repeat
Memo1.Lines.Add(JStringToString(C.getString(I))); // unforturnately... nothing comes here --- so I am guessing I am doing something wrong in creating the projection or calling the ContentResolver (??)

Inc(I);
until (C.isLast);


end;

Comments

  1. Brian Hamilton​, are there built in actions in Delphi for opening a media gallery which return the file path? Wow! Where can I find them?

    ReplyDelete
  2. there are functions like Androidapi.IOUtils.getExternalFilesDir + PathDelim

    ReplyDelete
  3. Hey Brian... what I am trying to do is give the use the interface of opening the media gallery and it does return the path but as an URI. Apparently, there are ways to convert URI into filepath... but it's not working. I am going putting it up on the main question... hang on...

    ReplyDelete

Post a Comment