Qt Android: where is my file if I write to "./myfile.txt"? - android

I am porting my Qt desktop app to Android.
In the desktop version, I will get a myfile.txt in the same folder of the executable file when I write to ./myfile.txt.
After I ported it to Android, the app runs smoothly but I cannot find the file anywhere as I'm new to Android...
So where is the file? Is there any concept like pwd for an Android app?
I'm using QFile and QTextStream to generate and write the file.
QFile file;
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream stream(&file);
stream << "something";
Thank you!

it might be in "application storage".
/data/data/com.example.yourAppPackageName/
or in sd-card application storage
/sdcard/Android/data/com.example.yourAppPackageName/

Related

Flutter app assets - unable to load files with names with non-latin characters

I have a quiz app with:
Video assets (over 1000 files, 750 MB) that can be downloaded using the download_assets package.
Image assets (also over 1000 files, 80 MB), bundled and deployed with the app.
Filenames are stored in a sqlite database.
I'm using Android Studio, macOS.
I wrote a function that takes filenames from a database and checks which files are on a device.
As it turned out, several of the video files are unavailable on Android devices (although they are visible in Device File Explorer). On iOS devices everything is OK.
Also some images are not available, but here on both iOS and Android devices.
I wrote Python script:
import os
import chardet
dir = '/path/to/directory/with/assets'
for n in os.listdir(dir):
if (chardet.detect(os.fsencode(n))['encoding'] != 'ascii'):
print ('{} => {} (confidence: {})'.format(n, chardet.detect(os.fsencode(n))['encoding'], chardet.detect(os.fsencode(n))['confidence']))
All files that work are encoded in ascii, the rest looks like this:
pięć5.mp4 => utf-8 (confidence: 0.7525)
JAZDA NOCĄorg.mp4 => ISO-8859-1 (confidence: 0.73)
Rowerzystę W17_2.mp4 => utf-8 (confidence: 0.505)
I tried renaming files in terminal. Then I tried to use the convmv utility. When I prepared a zip in terminal with only these 3 files it worked, but when I created a full archive, it turned out that two other files that worked fine before (and which had non-Latin characters in the name) stopped loading.
My final solution: I packed the two problem files in Finder (like the first archive). Then I added the rest of the files to the archive in the terminal:
zip assets.zip *.mp4
Now all video files load on both Android and iOS devices. But why?
I also solved the problem with the image files. I tried with mv and conmv in the terminal of course. I think it worked with at least one file (I'm not sure because I was in the dark and don't know what finally worked). I got stuck with a few files and that's when I found this link.
I used the Refactor->Rename option in Android Studio. I renamed the files to those that did not contain non-Latin characters (e.g. 313D12_a_org_światło.jpg to 313D12_a_org_swiatlo.jpg). I restarted the application. Then I renamed the files in Android Studio to the old ones. After restart all the files worked.
I am writing all this for two reasons:
Maybe someone will have similar problems and this description will be useful to him.
I am very curious what is causing this behavior. Especially, why files extracted from a zip will behave differently depending on how the zip is prepared and on which device it is used (Android or iOS).

Unity, JSON file - Android problem, can't find my JSON file

I wrote a script that allows you to read and write to a json file. As long as I tried the script in unity editor, I didn't have any problems. But when I switched to installing the application on an Android device, I can't find my json file.
The json file is called "playerData.json" and has been placed in a folder called "playerData.json".
This is the code for the path of the json file (working on unity but not working on android)
path = Application.streamingAssetsPath + "/playerData.json";
I tried using this string of code to get the code to work on android as well, but there is no way to get it to work.
path = System.IO.Path.Combine(Application.streamingAssetsPath, "/playerData.json");
I only wrote the line concerning the path as my android device cannot find the JSON file. Thanks everyone for the help!
Application.streamingAssetsPath does not work on Android and WebGL
It is not possible to access the StreamingAssets folder on WebGL and Android platforms. No file access is available on WebGL. Android uses a compressed .apk file. These platforms return a URL. Use the UnityWebRequest class to access the Assets.
There is a workaround though as mentioned using UnityWebRequest, can find an example in this Unity Answer

Copy file from assets to permanent location Qt + Android

I'm trying to copy a default initialized database packaged in the assets folder to an permanent location in an android device. For this I hav the following code:
QString db_file = "/my_db";
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
QFile assets_path("assets:" + db_file);
assets_path.copy(path + db_file);
QFile::setPermissions(path + db_file, QFileDevice::ReadUser |
QFileDevice::WriteUser);
And then I would go on to open the database in this new path, the thing is I'm getting the following error after the copy.
Copy error "Cannot create /data/user/0/org.qtproject.Demo/files/my_db for output"
What am I doing wrong?. Is also this the correct/proper way to do this?
Thanks.
Well aparently is a bug in Qt 5.10 prebuilt version, rolled back to Qt 5.9 and it works. Its a shame since I needed the QML translation functions.
https://bugreports.qt.io/browse/QTBUG-64103

How to use QFile on Android?

I need read .txt file on android using qt program. If build for windows, that file should be in build folder, but what about android? How to include it in apk?
You can include the text file into your APK's assets, and then refer to it like so:
QFile file( "assets:/qml/foo/main.qml" );
This question has another URI for accessing assets: How to add qt resources to android APK file?
Or you can package the QFile in your application as a QRC (http://qt-project.org/doc/qt-5.0/qtcore/resources.html) and access it like so:
QFile file( "qrc:/path/to/file.abc" );
Both of these options are read only.

Adobe Air for Android: Where is a xml file after instalation .apk file

An Air app which loading data from an external XML file (cfg.xml). I've published the Android/Air file, included the cfg.xml file in the Android package. Then I've installed on my SD Card(). App's reading xml file - working perfectly. But I need raw access(on my device) to cfg.xml I cannot find this file, checked everywhere(Rooted Phone). Where is it? Is there other solution? I need a file which is easy to read/write.
Use DDMS -> File Explorer and look for you app name in folders like data, ...
Solution:
Use fileStream instead of URLLoader
Change directory to SD Card e.g.
File.userDirectory.resolvePath("YourAppData/cfg.xml")
(No rooted phone needed)

Categories

Resources