How to open a file in android with qt having the content URI

1.6k Views Asked by At

How do i open a file with QFile with link in android -content://com.android.providers.downloads.documents/document/raw.pdf

I tried below code but its showing that the file not open

 QString path("content://com.android.providers.downloads.documents/document/raw.pdf");
 QUrl path_url(path);
 path = path_url.toLocalFile();
 QFile* file = new QFile(path);
 file->open(QIODevice::ReadOnly)
1

There are 1 best solutions below

0
Ashif On

QQmlFile could format it to /storage/emulated/0/....

QString path("content://com.android.providers.downloads.documents/document/raw.pdf"); QUrl url(path);

QFile file(QQmlFile::urlToLocalFileOrQrc(url));
  if (!file.open(QFile::ReadOnly)) {
    emit error(tr("Could not open file. '%1'").arg(file.errorString()));
    return;
  } 

example for detail implementation.