How to get android <shared-storage> path from Qt?

I had to upload a separate extension file with my application (developed in Qt) in the Google Play console. This is a simple rcc file. I have a file name after downloading (it appears on the Google console page). But I can not find any information on how to get a common storage path (as mentioned) on the Android docs page ( http://developer.android.com/google/play/expansion-files.html#StorageLocation ).

I came across this question ( How to add Android extension files using Qt ), where the user seems to have solved the problem, but does not give any details on how to get a common storage path.

+2
source share
2 answers

I decided:

I converted qrc containing large files to a binary using the qt rcc tool , then I used the following code to call the correct methods from Qt Android Activity and get the correct path to the extension files:

QAndroidJniObject mediaDir = QAndroidJniObject::callStaticObjectMethod("android/os/Environment", "getExternalStorageDirectory", "()Ljava/io/File;");
QAndroidJniObject mediaPath = mediaDir.callObjectMethod( "getAbsolutePath", "()Ljava/lang/String;" );
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
QAndroidJniObject package = activity.callObjectMethod("getPackageName", "()Ljava/lang/String;");

QString dataAbsPath = mediaPath.toString()+"/Android/obb/"+package.toString()+"/yourExpansionFileName.obb";

QAndroidJniEnvironment env; // Don't know what this is for ? 
if (env->ExceptionCheck()) { env->ExceptionClear(); } // Or this...?

bool loadResource = QResource::registerResource(dataAbsPath);

Remember to add this manifest resolution (as the extension file is in external storage) #include <QAndroidJniEnvironment>to your application (and QT += androidextrasprofile) and last time:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

I did not check if the file was there or not before downloading (each device tested worked directly), but the android docs say that you may need to download it manually. There are also some tricks for downloading extension files, you can add them only with the second sending apk (on Google Play).

+5
source

.

QStringList systemEnvironment = QProcess::systemEnvironment();

  • EXTERNAL_STORAGE =///
  • EXTERNAL_ADD_STORAGE =//external_sd
  • SECONDARY_STORAGE =//external_sd
  • ...
0

All Articles