imaginate301 |
29-02-2024 19:22:51 |
obtener ruta de archivo del explorador android
Buenas tardes, estoy intentando obtener la ruta de un archivo seleccionado desde el explorador de archivos por defecto de android.
Este procedimiento para abrirlo
Código Delphi [-]procedure TForm15.OpenFileSelector;
var
Intent: JIntent;
begin
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_OPEN_DOCUMENT);
Intent.setType(StringToJString('*/*')); Intent.addCategory(TJIntent.JavaClass.CATEGORY_OPENABLE);
SharedActivity.startActivityForResult(Intent, 0);
end;
Esta funcion para obtener la ruta
Código Delphi [-]function TForm15.GetSelectedFilePath(const Intent: JIntent): string;
var
Uri: Jnet_Uri;
Cursor: JCursor;
ColumnIndex: Integer;
FilePath: string;
begin
Result := '';
Uri := Intent.getData;
if Assigned(Uri) then
begin
Cursor := SharedActivity.getContentResolver.query(Uri, nil, nil, nil, nil);
if Assigned(Cursor) then
begin
ColumnIndex := Cursor.getColumnIndexOrThrow(TJMediaStore_MediaColumns.JavaClass.DATA);
Cursor.moveToFirst;
FilePath := JStringToString(Cursor.getString(ColumnIndex));
Cursor.close;
Result := FilePath;
end;
end;
end;
y este para recibir la notificacion :
Código Delphi [-]procedure TForm15.HandleActivityMessage(const Sender: TObject; const M: TMessage);
var
ResultNotification: TMessageResultNotification;
SelectedFilePath: string;
begin
if M is TMessageResultNotification then
begin
ResultNotification := TMessageResultNotification(M);
if ResultNotification.RequestCode = 0 then
begin
if ResultNotification.ResultCode = TJActivity.JavaClass.RESULT_OK then
begin
SelectedFilePath := GetSelectedFilePath(ResultNotification.Value);
ShowMessage('Ruta del archivo seleccionado: ' + SelectedFilePath);
rutapdf.Text:= SelectedFilePath;
end;
end;
end;
end;
Utilizo el servicio de mensajeria de delphi
Código Delphi [-]TMessageManager.DefaultManager.SubscribeToMessage(TMessageResultNotification, HandleActivityMessage);
En teoria lo guarda en un edit llamado rutapdf
En versiones anteriores a android 14 si me funciona, pero lo instalo en otro movil con android 14 y se bloquea al llamar al servicio de mensajeria.
Alguien me puede ayudar porfavor??
|