Skip to content

Commit

Permalink
fix(android): handle home uri when picking folder
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Aug 11, 2022
1 parent 010c008 commit 471b52b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions android/app/src/main/java/com/logseq/app/FileUtil.java
Expand Up @@ -14,8 +14,10 @@

import java.io.File;

// The following refs
// https://stackoverflow.com/questions/29713587/how-to-get-the-real-path-with-action-open-document-tree-intent
// https://gist.github.com/asifmujteba/d89ba9074bc941de1eaa#file-asfurihelper
// with bug fixes and patches.
public class FileUtil {
@TargetApi(Build.VERSION_CODES.KITKAT)
public static String getPath(final Context context, final Uri uri) {
Expand All @@ -29,17 +31,20 @@ public static String getPath(final Context context, final Uri uri) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];

if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/" + split[1];
}

// NOTE: It's not a good idea to use storage root as Graph root.
String remain = "";
if (split.length == 2) {
remain = split[1];
}

if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/" + remain;
} else if ("home".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/Documents/" + remain;
} else if ("downloads".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/Download/" + remain; // No 's' here
}

File dir = null;
File[] mdirs = context.getExternalMediaDirs();
for (File mdir : mdirs) {
Expand Down

0 comments on commit 471b52b

Please sign in to comment.