use of android.webkit.MimeTypeMap in project Signal-Android by WhisperSystems.
the class SaveAttachmentTask method generateOutputFileName.
private String generateOutputFileName(@NonNull String contentType, long timestamp) {
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String extension = mimeTypeMap.getExtensionFromMimeType(contentType);
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss-SSS");
String base = "signal-" + dateFormatter.format(timestamp);
if (extension == null)
extension = "attach";
return base + "." + extension;
}
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();
}
}
use of android.webkit.MimeTypeMap in project AndLang by wugemu.
the class HttpU method downAPK.
public long downAPK(Context mContext, String url, String filename) {
// 获取okHttp对象get请求
try {
// 创建下载任务
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
// 漫游网络是否可以下载
request.setAllowedOverRoaming(true);
// 设置文件类型,可以在下载结束后自动打开该文件
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String mimeString = mimeTypeMap.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(url));
request.setMimeType(mimeString);
// 在通知栏中显示,默认就是显示的
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
request.setVisibleInDownloadsUi(true);
// sdcard的目录下的download文件夹,必须设置
request.setDestinationInExternalPublicDir("/" + BaseLangApplication.tmpImageDir + "/", filename);
// 将下载请求加入下载队列
DownloadManager downloadManager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
// 通过该id可以取消任务,重启任务等等,看上面源码中框起来的方法
if (downloadManager != null) {
long downloadId = downloadManager.enqueue(request);
return downloadId;
}
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
use of android.webkit.MimeTypeMap in project AmazeFileManager by TeamAmaze.
the class MimeTypes method getMimeType.
/**
* Get Mime Type of a file
*
* @param path the file of which mime type to get
* @return Mime type in form of String
*/
public static String getMimeType(String path, boolean isDirectory) {
if (isDirectory) {
return null;
}
String type = ALL_MIME_TYPES;
final String extension = getExtension(path);
// mapping extension to system mime types
if (extension != null && !extension.isEmpty()) {
final String extensionLowerCase = extension.toLowerCase(Locale.getDefault());
final MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extensionLowerCase);
if (type == null) {
type = MIME_TYPES.get(extensionLowerCase);
}
}
if (type == null)
type = ALL_MIME_TYPES;
return type;
}
use of android.webkit.MimeTypeMap in project qksms by moezbhatti.
the class VideoModel method initFromFile.
private void initFromFile(Uri uri) {
String path = uri.getPath();
mSrc = path.substring(path.lastIndexOf('/') + 1);
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String extension = MimeTypeMap.getFileExtensionFromUrl(mSrc);
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 = mSrc.lastIndexOf('.');
if (0 <= dotPos) {
extension = mSrc.substring(dotPos + 1);
}
}
mContentType = mimeTypeMap.getMimeTypeFromExtension(extension);
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
Log.v(TAG, "New VideoModel initFromFile created:" + " mSrc=" + mSrc + " mContentType=" + mContentType + " mUri=" + uri);
}
}
Aggregations