Using Qt 5.14.2, with NDK r21b, I create this simple program:
#include <QApplication>
#include <QDialog>
#include <QLabel>
#include <QDir>
#include <QStandardPaths>
#include <QFile>
#include <QTextStream>
#include <QVBoxLayout>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDialog dlg;
dlg.setLayout( new QVBoxLayout() );
QString path = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
if ( !QDir(path).exists() )
{
if ( QDir().mkdir(path) )
dlg.layout()->addWidget( new QLabel( "Could create folder " + path, &dlg ) );
else
dlg.layout()->addWidget( new QLabel( "Could NOT create folder " + path, &dlg ) );
}
else
{
dlg.layout()->addWidget( new QLabel( "Folder exists " + path, &dlg ) );
}
path += "/from_qt.txt";
QFile file(path);
if (file.open(QIODevice::ReadWrite))
{
QTextStream stream(&file);
stream << "something" << endl;
dlg.layout()->addWidget( new QLabel( "Could create file " + path, &dlg ) );
}
else
{
dlg.layout()->addWidget( new QLabel( "Could NOT create file " + path, &dlg ) );
}
dlg.show();
return a.exec();
}
I add android.permission.WRITE_EXTERNAL_STORAGE
to AndroidManifest.xml
file.
- Using Android 5, when installing the apk, the system reports the app needs to access storage and later the app will work (it reports
Could NOT create...
).
- Using Android 6, when installing the apk, the system does not report the app needs any special access and later the app will work.
question from:
https://stackoverflow.com/questions/65935980/qt-app-permissions-not-granted-on-recent-6-android-devices 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…