3

I've had to upload a separate expansion file with my app (developed in Qt) in Google Play console. It's a simple rcc file. I have the name of file after the upload (it shows on the google console page). But I can't seem to find any info o how to get the shared-storage path (as mentioned) on the Android docs page (http://developer.android.com/google/play/expansion-files.html#StorageLocation).

I did come across this question (How to add android expansion files using Qt) where the user seems to have solved the issue but doesn't give any details on how to get the shared-storage path.

Community
  • 1
  • 1
Gabriel
  • 176
  • 1
  • 12

3 Answers3

7

I've solved it:

I converted a qrc containing the large files to a binary using the qt rcc tool, then I used the following code to call the proper methods from the Qt Android Activity and retrieve the correct path to the expansion 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);

Don't forget to add #include <QAndroidJniEnvironment> in your app (and QT += androidextras in pro file), and last add this permission to the manifest (as the expansion file is located inside the external storage):

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

I didn't check if the file was there or not before loading (every device I tested worked straight), but the android docs say you might need to download it manually. There is also some catch to uploading expansion files, you can only add them with the second apk submission (in Google play).

Gabriel
  • 176
  • 1
  • 12
  • 1
    The env object gives you the possibility to check if an exception occurred when calling Java methods through JNI. You check if any exception has occurred and then you clear/handle them. If you continue without doing so your program might become unstable and crash (have not been experiencing this myself). – uniquenamehere Aug 17 '15 at 21:34
1

This code may be help you.

QStringList systemEnvironment = QProcess::systemEnvironment();

looking for

  1. EXTERNAL_STORAGE=/storage/emulated/legacy
  2. EXTERNAL_ADD_STORAGE=/storage/external_SD
  3. SECONDARY_STORAGE=/storage/external_SD
  4. ...
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
0

This code worked for me:

QString s = QStandardPaths::writableLocation(QStandardPaths::movieLoaction);
QDir MyDir;
s = s + "/MyFolder"
MyDir.mkdir(s);

In your Android device you must check the storage permissions for your application. If not add this permission then run the application.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
ali.sh
  • 1
  • 3