Skip to content

Commit

Permalink
Querying android version directly from Qt, replaced convoluted castin…
Browse files Browse the repository at this point in the history
…g in mediaStore
  • Loading branch information
paulondcdev committed Aug 30, 2016
1 parent b9a5231 commit 1fb5cfa
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions source/cpp/nativefiledialogandroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ void NativeFileDialogAndroid::open(QUrl initialFolder=QUrl()) {
QAndroidJniObject intent("android/content/Intent");
QString contentType;

// querying the buildVersion to make sure the multiple selection feature is available
int buildVersion = QAndroidJniObject::getStaticField<jint>("android/os/Build$VERSION", "SDK_INT");

if (m_selectMultiple && buildVersion >= 19) {
// querying the android version to make sure the multiple selection feature is available
if (m_selectMultiple && QtAndroid::androidSdkVersion() >= 19) {
intent.callObjectMethod("putExtra","(Ljava/lang/String;Z)Landroid/content/Intent;",
QAndroidJniObject::getStaticObjectField("android/content/Intent", "EXTRA_ALLOW_MULTIPLE", "Ljava/lang/String;").object<jobject>(), true);
}
Expand Down Expand Up @@ -117,13 +115,14 @@ QString NativeFileDialogAndroid::filePath(QAndroidJniObject & uri) {
// otherwise query the file path through content resolver
else {


QAndroidJniEnvironment env;

QAndroidJniObject mediaStore = QAndroidJniObject::getStaticObjectField("android/provider/MediaStore$MediaColumns", "DATA", "Ljava/lang/String;");

jobjectArray projection = (jobjectArray)env->NewObjectArray(1, env->FindClass("java/lang/String"), env->NewStringUTF(""));

env->SetObjectArrayElement(projection, 0, env->NewStringUTF(mediaStore.toString().toStdString().c_str()));
env->SetObjectArrayElement(projection, 0, mediaStore.object<jstring>());

QAndroidJniObject contentResolver = QtAndroid::androidActivity().callObjectMethod("getContentResolver", "()Landroid/content/ContentResolver;");

Expand Down

0 comments on commit 1fb5cfa

Please sign in to comment.