* Returns writable application-specific directories on all external storage volumes. * * These directories are named "Android/data/PACKAGENAME" and use "synthesized * permissions", i.e. apps from the package may write to these folders without needing * explicit permissions. Other apps may read these files. * * Files in this location will be deleted when the app is uninstalled. * * Requi
| 100 | * \see https://developer.android.com/reference/android/content/Context.html#getExternalFilesDirs(java.lang.String) |
| 101 | */ |
| 102 | std::vector<QString> getExternalFilesDirs(jstring* type) |
| 103 | { |
| 104 | auto activity = QtAndroid::androidActivity(); |
| 105 | auto context = activity.callObjectMethod( |
| 106 | "getApplicationContext", |
| 107 | "()Landroid/content/Context;"); |
| 108 | |
| 109 | // Get directories with synthesized permissions on all external storage volumes |
| 110 | auto external_files_dirs = context.callObjectMethod( |
| 111 | "getExternalFilesDirs", |
| 112 | "(Ljava/lang/String;)[Ljava/io/File;", |
| 113 | type); |
| 114 | |
| 115 | QAndroidJniEnvironment jni; |
| 116 | const auto length = jni->GetArrayLength(external_files_dirs.object<jarray>()); |
| 117 | |
| 118 | std::vector<QString> locations; |
| 119 | locations.reserve(std::size_t(length)); |
| 120 | for (auto i = 0; i < length; ++i) |
| 121 | { |
| 122 | auto location_jni = jni->GetObjectArrayElement(external_files_dirs.object<jobjectArray>(), i); |
| 123 | auto location = QAndroidJniObject{ location_jni }.toString(); |
| 124 | |
| 125 | const auto warning_path = QString(location + QLatin1String("/README.html")); |
| 126 | QFile warning(warning_path); |
| 127 | if (warning.open(QIODevice::WriteOnly | QIODevice::Truncate)) |
| 128 | { |
| 129 | auto android_start = location.indexOf(QLatin1String("/Android/data/")); |
| 130 | warning.write("<html><body><p>\n"); |
| 131 | warning.write(StorageLocation::fileHintTextTemplate(StorageLocation::HintApplication).arg(location.mid(android_start+1)).toUtf8()); |
| 132 | warning.write("\n</p></body></html>"); |
| 133 | warning.close(); |
| 134 | locations.push_back(location); |
| 135 | mediaScannerScanFile(warning_path); |
| 136 | } |
| 137 | } |
| 138 | return locations; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Constructs a list of OOMapper folders on secondary storage volumes |
no test coverage detected