mirror of https://github.com/logseq/logseq
fix(android): handle exteral storage
parent
a887810751
commit
3e78139da2
|
@ -10,6 +10,9 @@ import android.os.Environment;
|
|||
import android.provider.DocumentsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
// 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
|
||||
|
@ -31,7 +34,26 @@ public class FileUtil {
|
|||
return Environment.getExternalStorageDirectory() + "/" + split[1];
|
||||
}
|
||||
|
||||
// TODO handle non-primary volumes
|
||||
// NOTE: It's not a good idea to use storage root as Graph root.
|
||||
String relPath = "";
|
||||
if (split.length == 2) {
|
||||
relPath = split[1];
|
||||
}
|
||||
|
||||
String storageState = Environment.getExternalStorageState();
|
||||
if (storageState.equals(Environment.MEDIA_MOUNTED)) {
|
||||
// attempt 1
|
||||
File dir = new File("/storage/" + type + "/" + relPath);
|
||||
if (dir.exists()) {
|
||||
return dir.getPath();
|
||||
}
|
||||
// attempt 2
|
||||
dir = new File("/mnt/" + type + "/" + relPath);
|
||||
if (dir.exists()) {
|
||||
return dir.getPath();
|
||||
}
|
||||
}
|
||||
// TODO: other cases
|
||||
} else if (isDownloadsDocument(uri)) {
|
||||
final String id = DocumentsContract.getDocumentId(uri);
|
||||
if (!TextUtils.isEmpty(id)) {
|
||||
|
@ -67,7 +89,6 @@ public class FileUtil {
|
|||
return getDataColumn(context, contentUri, selection, selectionArgs);
|
||||
}
|
||||
} else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
||||
|
||||
// Return the remote address
|
||||
if (isGooglePhotosUri(uri))
|
||||
return uri.getLastPathSegment();
|
||||
|
|
|
@ -58,7 +58,13 @@ public class FolderPicker extends Plugin {
|
|||
Uri docUri = DocumentsContract.buildDocumentUriUsingTree(treeUri,
|
||||
DocumentsContract.getTreeDocumentId(treeUri));
|
||||
Log.i("Logseq/FolderPicker", "Got uri " + docUri);
|
||||
ret.put("path", FileUtil.getPath(context, docUri));
|
||||
call.resolve(ret);
|
||||
String path = FileUtil.getPath(context, docUri);
|
||||
Log.i("Logseq/FolderPicker", "Convert to path " + FileUtil.getPath(context, docUri));
|
||||
if (path == null || path.isEmpty()) {
|
||||
call.reject("Cannot support this directory type: " + docUri);
|
||||
} else {
|
||||
ret.put("path", path);
|
||||
call.resolve(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -308,7 +308,10 @@
|
|||
(open-dir [_this _ok-handler]
|
||||
(p/let [_ (when (= (mobile-util/platform) "android") (check-permission-android))
|
||||
{:keys [path localDocumentsPath]} (p/chain
|
||||
(.pickFolder mobile-util/folder-picker)
|
||||
(p/catch (.pickFolder mobile-util/folder-picker)
|
||||
(fn [e]
|
||||
(js/alert (str e))
|
||||
nil)) ;; NOTE: Can not pick folder, let it crash
|
||||
#(js->clj % :keywordize-keys true))
|
||||
_ (when (and (mobile-util/native-ios?)
|
||||
(not (or (local-container-path? path localDocumentsPath)
|
||||
|
|
Loading…
Reference in New Issue