android: add folder picker

pull/3175/head
Weihua Lu 2021-09-18 14:29:39 +08:00 committed by Tienson Qin
parent a4db23cb78
commit 7e5a364d18
2 changed files with 42 additions and 1 deletions

View File

@ -0,0 +1,33 @@
package com.logseq.app;
import android.content.Intent;
import androidx.activity.result.ActivityResult;
import com.getcapacitor.JSObject;
import com.getcapacitor.Plugin;
import com.getcapacitor.annotation.ActivityCallback;
import com.getcapacitor.annotation.CapacitorPlugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
@CapacitorPlugin(name = "FolderPicker")
public class FolderPicker extends Plugin {
@PluginMethod()
public void pickFolder(PluginCall call) {
Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
i.addCategory(Intent.CATEGORY_DEFAULT);
startActivityForResult(call, i, "folderPickerResult");
}
@ActivityCallback
private void folderPickerResult(PluginCall call, ActivityResult result) {
if (call == null) {
return;
}
JSObject ret = new JSObject();
ret.put("result", result.getData().getData());
call.resolve(ret);
}
}

View File

@ -1,5 +1,13 @@
package com.logseq.app;
import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
public class MainActivity extends BridgeActivity {}
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerPlugin(FolderPicker.class);
}
}