Skip to content

Commit

Permalink
TermuxFilePickerProvider: Small improvements
Browse files Browse the repository at this point in the history
1. Return true from onCreate().
2. Implement getType().
  • Loading branch information
fornwall committed Feb 13, 2016
1 parent d0015cb commit ce7ad53
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.support.annotation.NonNull;
import android.webkit.MimeTypeMap;

import java.io.File;
import java.io.FileNotFoundException;
Expand All @@ -15,7 +16,7 @@
public class TermuxFilePickerProvider extends ContentProvider {
@Override
public boolean onCreate() {
return false;
return true;
}

@Override
Expand All @@ -25,7 +26,20 @@ public Cursor query(@NonNull Uri uri, String[] projection, String selection, Str

@Override
public String getType(@NonNull Uri uri) {
return null;
String contentType = null;
String path = uri.getPath();
int lastDotIndex = path.lastIndexOf('.');
String possibleFileExtension = path.substring(lastDotIndex + 1, path.length());
if (possibleFileExtension.contains("/")) {
// The dot was in the path, so not a file extension.
} else {
MimeTypeMap mimeTypes = MimeTypeMap.getSingleton();
// Lower casing makes it work with e.g. "JPG":
contentType = mimeTypes.getMimeTypeFromExtension(possibleFileExtension.toLowerCase());
}

if (contentType == null) contentType = "application/octet-stream";
return contentType;
}

@Override
Expand Down

0 comments on commit ce7ad53

Please sign in to comment.