Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): handle home uri when picking folder #6328

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions android/app/src/main/java/com/logseq/app/FileUtil.java
Original file line number Diff line number Diff line change
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