Skip to content

Commit

Permalink
Put back missing getSDCardPath method
Browse files Browse the repository at this point in the history
  • Loading branch information
DonLakeFlyer committed Dec 10, 2024
1 parent be9c439 commit 0141494
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion android/src/AndroidInterface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ QString getSDCardPath()

const QJniObject result = QJniObject::callStaticObjectMethod(kJniQGCActivityClassName, "getSDCardPath", "()Ljava/lang/String;");
if (!result.isValid()) {
qCWarning(AndroidInterfaceLog) << "Invalid Result";
qCWarning(AndroidInterfaceLog) << "Call to java getSDCardPath failed: Invalid Result";
return QString();
}

Expand Down
35 changes: 35 additions & 0 deletions android/src/org/mavlink/qgroundcontrol/QGCActivity.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package org.mavlink.qgroundcontrol;

import java.util.List;
import java.lang.reflect.Method;

import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import android.net.wifi.WifiManager;
import android.util.Log;
import android.view.WindowManager;
import android.app.Activity;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;

import org.qtproject.qt.android.bindings.QtActivity;

Expand Down Expand Up @@ -110,6 +116,35 @@ private void releaseMulticastLock() {
}
}

public static String getSDCardPath() {
StorageManager storageManager = (StorageManager)m_instance.getSystemService(Activity.STORAGE_SERVICE);
List<StorageVolume> volumes = storageManager.getStorageVolumes();
Method mMethodGetPath;
String path = "";
for (StorageVolume vol : volumes) {
try {
mMethodGetPath = vol.getClass().getMethod("getPath");
} catch (NoSuchMethodException e) {
e.printStackTrace();
continue;
}
try {
path = (String) mMethodGetPath.invoke(vol);
} catch (Exception e) {
e.printStackTrace();
continue;
}

if (vol.isRemovable() == true) {
Log.i(TAG, "removable sd card mounted " + path);
return path;
} else {
Log.i(TAG, "storage mounted " + path);
}
}
return "";
}

// Native C++ functions
public native boolean nativeInit();
public native void qgcLogDebug(final String message);
Expand Down

0 comments on commit 0141494

Please sign in to comment.