Skip to content

Commit

Permalink
fix: android 10 file access
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Dec 8, 2021
1 parent f983452 commit b9fcfdd
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion android/app/src/main/java/com/logseq/app/FolderPicker.java
Expand Up @@ -5,6 +5,7 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.os.Build;
import android.provider.DocumentsContract;
import android.provider.Settings;

Expand All @@ -21,9 +22,19 @@

@CapacitorPlugin(name = "FolderPicker")
public class FolderPicker extends Plugin {
public static boolean FileAccessAllowed()
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
return true;
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return (Environment.isExternalStorageManager());
}
return false;
}

@PluginMethod()
public void pickFolder(PluginCall call) {
if (Environment.isExternalStorageManager()) {
if (FileAccessAllowed()) {
Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
i.addCategory(Intent.CATEGORY_DEFAULT);
startActivityForResult(call, i, "folderPickerResult");
Expand Down

0 comments on commit b9fcfdd

Please sign in to comment.