use of android.webkit.MimeTypeMap in project mobile-android by photo.
the class NewPhotoObserver method getMimeType.
/**
* Get the mime type for the file
*
* @param file
* @return
*/
public static String getMimeType(File file) {
String type = null;
String extension = MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).getPath());
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension.toLowerCase());
}
CommonUtils.debug(TAG, "File: %1$s; extension %2$s; MimeType: %3$s", file.getAbsolutePath(), extension, type);
return type;
}
use of android.webkit.MimeTypeMap in project qksms by moezbhatti.
the class UriImage method initFromFile.
private void initFromFile(Context context, Uri uri) {
mPath = uri.getPath();
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String extension = MimeTypeMap.getFileExtensionFromUrl(mPath);
if (TextUtils.isEmpty(extension)) {
// getMimeTypeFromExtension() doesn't handle spaces in filenames nor can it handle
// urlEncoded strings. Let's try one last time at finding the extension.
int dotPos = mPath.lastIndexOf('.');
if (0 <= dotPos) {
extension = mPath.substring(dotPos + 1);
}
}
mContentType = mimeTypeMap.getMimeTypeFromExtension(extension);
// It's ok if mContentType is null. Eventually we'll show a toast telling the
// user the picture couldn't be attached.
buildSrcFromPath();
}
use of android.webkit.MimeTypeMap in project Signal-Android by WhisperSystems.
the class SaveAttachmentTask method constructOutputFile.
private File constructOutputFile(String contentType, long timestamp) throws IOException {
File sdCard = Environment.getExternalStorageDirectory();
File outputDirectory;
if (contentType.startsWith("video/")) {
outputDirectory = new File(sdCard.getAbsoluteFile() + File.separator + Environment.DIRECTORY_MOVIES);
} else if (contentType.startsWith("audio/")) {
outputDirectory = new File(sdCard.getAbsolutePath() + File.separator + Environment.DIRECTORY_MUSIC);
} else if (contentType.startsWith("image/")) {
outputDirectory = new File(sdCard.getAbsolutePath() + File.separator + Environment.DIRECTORY_PICTURES);
} else {
outputDirectory = new File(sdCard.getAbsolutePath() + File.separator + Environment.DIRECTORY_DOWNLOADS);
}
if (!outputDirectory.mkdirs())
Log.w(TAG, "mkdirs() returned false, attempting to continue");
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String extension = mimeTypeMap.getExtensionFromMimeType(contentType);
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd-HHmmss");
String base = "signal-" + dateFormatter.format(timestamp);
if (extension == null)
extension = "attach";
int i = 0;
File file = new File(outputDirectory, base + "." + extension);
while (file.exists()) {
file = new File(outputDirectory, base + "-" + (++i) + "." + extension);
}
return file;
}
use of android.webkit.MimeTypeMap in project material-dialogs by afollestad.
the class FileChooserDialog method listFiles.
File[] listFiles(@Nullable String mimeType, @Nullable String[] extensions) {
File[] contents = parentFolder.listFiles();
List<File> results = new ArrayList<>();
if (contents != null) {
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
for (File fi : contents) {
if (fi.isDirectory()) {
results.add(fi);
} else {
if (extensions != null) {
boolean found = false;
for (String ext : extensions) {
if (fi.getName().toLowerCase().endsWith(ext.toLowerCase())) {
found = true;
break;
}
}
if (found) {
results.add(fi);
}
} else if (mimeType != null) {
if (fileIsMimeType(fi, mimeType, mimeTypeMap)) {
results.add(fi);
}
}
}
}
Collections.sort(results, new FileSorter());
return results.toArray(new File[results.size()]);
}
return null;
}
use of android.webkit.MimeTypeMap in project UltimateRecyclerView by cymcsg.
the class DataUtil method openFileInSystem.
public static void openFileInSystem(String path, Context context) {
try {
MimeTypeMap myMime = MimeTypeMap.getSingleton();
Intent newIntent = new Intent(Intent.ACTION_VIEW);
String mimeType = myMime.getMimeTypeFromExtension(fileExt(path).substring(1));
newIntent.setDataAndType(Uri.fromFile(new File(path)), mimeType);
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(newIntent);
} catch (Exception e) {
Toast.makeText(context, "No handler for this type of file.", Toast.LENGTH_LONG).show();
}
}
Aggregations