Skip to content

Commit

Permalink
android: fixed backward compatibility target folder for android <30. …
Browse files Browse the repository at this point in the history
…Open: files are sorted by last modified date.
  • Loading branch information
matlabbe committed Jan 30, 2022
1 parent 4d8c1d8 commit 20d873c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 32 deletions.
1 change: 0 additions & 1 deletion app/android/AndroidManifest.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Expand Down
50 changes: 21 additions & 29 deletions app/android/src/com/introlab/rtabmap/RTABMapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public void run() {
}

public void onServiceDisconnected(ComponentName name) {
// Handle this if you need to gracefully shutsaveDatabasedown/retry
// Handle this if you need to gracefully shutdown/retry
// in the event that Tango itself crashes/gets upgraded while running.
mToast.makeText(getApplicationContext(),
String.format("Tango disconnected!"), mToast.LENGTH_LONG).show();
Expand Down Expand Up @@ -504,10 +504,28 @@ public void onClick(DialogInterface dialog, int which) {
mTotalLoopClosures = 0;
mLastFastMovementNotificationStamp = System.currentTimeMillis()/1000;


int targetSdkVersion= 0;
try {
ApplicationInfo app = this.getPackageManager().getApplicationInfo("com.introlab.rtabmap", 0);
targetSdkVersion = app.targetSdkVersion;
} catch (NameNotFoundException e) {
e.printStackTrace();
}

if(Environment.getExternalStorageState().compareTo(Environment.MEDIA_MOUNTED)==0 &&
getActivity().getExternalFilesDirs(null).length >=1)
(targetSdkVersion < 30 || getActivity().getExternalFilesDirs(null).length >=1))
{
File extStore = getActivity().getExternalFilesDirs(null)[0];
File extStore;
if(targetSdkVersion < 30)
{
extStore = Environment.getExternalStorageDirectory();
}
else // >= android30
{
extStore = getActivity().getExternalFilesDirs(null)[0];
}

mWorkingDirectory = extStore.getAbsolutePath() + "/" + getString(R.string.app_name) + "/";
extStore = new File(mWorkingDirectory);
extStore.mkdirs();
Expand Down Expand Up @@ -3660,32 +3678,6 @@ public void run() {
final File f = new File(zipOutput);
final int fileSizeMB = (int)f.length()/(1024 * 1024);

// Save to public Documents/RTAB-Map folder
/*ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DISPLAY_NAME, fileName); //file name
values.put(MediaStore.MediaColumns.MIME_TYPE, "application/zip"); //file extension, will automatically add to file
values.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOCUMENTS + "/RTAB-Map"); //end "/" is not mandatory
Uri uri = getContentResolver().insert(MediaStore.Files.getContentUri("external"),values);
if (uri != null) {
OutputStream out;
try {
out = getApplicationContext().getContentResolver().openOutputStream(uri);
InputStream in = new FileInputStream(zipOutput);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
f.delete(); // remove private file
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
} */

// Send to...
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
Expand Down
25 changes: 24 additions & 1 deletion app/android/src/com/introlab/rtabmap/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

Expand Down Expand Up @@ -55,7 +59,7 @@ public static void zip(String[] files, String zipFile) throws IOException {
}
}

public static String[] loadFileList(String directory, final boolean databasesOnly) {
public static String[] loadFileList(final String directory, final boolean databasesOnly) {
File path = new File(directory);
String fileList[];
try {
Expand Down Expand Up @@ -83,6 +87,25 @@ public boolean accept(File dir, String filename) {
};
fileList = path.list(filter);
Arrays.sort(fileList);
List<String> fileListt = new ArrayList<String>(Arrays.asList(fileList));
Collections.sort(fileListt, new Comparator<String>() {

@Override
public int compare(String filename1, String filename2) {
File file1 = new File(directory+"/"+filename1);
File file2 = new File(directory+"/"+filename2);
long k = file1.lastModified() - file2.lastModified();
if(k > 0){
return -1;
}else if(k == 0){
return 0;
}else{
return 1;
}
}
});
fileListt.toArray(fileList);

}
else {
fileList = new String[0];
Expand Down
2 changes: 1 addition & 1 deletion corelib/src/util3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2858,7 +2858,7 @@ std::vector<std::pair< std::pair<int, int>, pcl::PointXY> > projectCloudToCamera
UINFO("maxDistance=%f", maxDistance);
UINFO("maxAngle=%f", maxAngle);
UINFO("distanceToCamPolicy=%s", distanceToCamPolicy?"true":"false");
UINFO("roiRatios=%s", roiRatios.size() == 4?uFormat("%f %f %f %f", roiRatios[0], roiRatios[1], roiRatios[2], roiRatios[3]):"");
UINFO("roiRatios=%s", roiRatios.size() == 4?uFormat("%f %f %f %f", roiRatios[0], roiRatios[1], roiRatios[2], roiRatios[3]).c_str():"");
UINFO("projMask=%dx%d", projMask.cols, projMask.rows);
std::vector<std::pair< std::pair<int, int>, pcl::PointXY> > pointToPixel;

Expand Down

0 comments on commit 20d873c

Please sign in to comment.