Skip to content

Commit

Permalink
Support looking up directories from file picker
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Oct 23, 2020
1 parent a1e8719 commit 6e49951
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 6 additions & 2 deletions app/GoNativeActivity.java
Expand Up @@ -134,13 +134,17 @@ static void showFileOpen(String mimes) {

void doShowFileOpen(String mimes) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
if (mimes.contains("|") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if ("application/x-directory".equals(mimes) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); // ask for a directory picker if OS supports it
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else if (mimes.contains("|") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimes.split("\\|"));
intent.addCategory(Intent.CATEGORY_OPENABLE);
} else {
intent.setType(mimes);
intent.addCategory(Intent.CATEGORY_OPENABLE);
}
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(Intent.createChooser(intent, "Open File"), FILE_OPEN_CODE);
}

Expand Down
13 changes: 9 additions & 4 deletions app/darwin_ios.m
Expand Up @@ -299,12 +299,17 @@ void showFileOpenPicker(char* mimes, char *exts) {
NSMutableArray *docTypes = [NSMutableArray array];
if (mimes != NULL && strlen(mimes) > 0) {
NSString *mimeList = [NSString stringWithUTF8String:mimes];
NSArray *mimeItems = [mimeList componentsSeparatedByString:@"|"];

for (NSString *mime in mimeItems) {
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mime, NULL);
if ([mimeList isEqualToString:@"application/x-directory"]) {
[docTypes addObject:kUTTypeFolder];
} else {
NSArray *mimeItems = [mimeList componentsSeparatedByString:@"|"];

[docTypes addObject:UTI];
for (NSString *mime in mimeItems) {
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mime, NULL);

[docTypes addObject:UTI];
}
}
} else if (exts != NULL && strlen(exts) > 0) {
NSString *extList = [NSString stringWithUTF8String:exts];
Expand Down

0 comments on commit 6e49951

Please sign in to comment.