Search in sources :

Example 26 with MimeTypeMap

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;
}
Also used : MimeTypeMap(android.webkit.MimeTypeMap) SimpleDateFormat(java.text.SimpleDateFormat)

Example 27 with MimeTypeMap

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();
    }
}
Also used : Intent(android.content.Intent) MimeTypeMap(android.webkit.MimeTypeMap) File(java.io.File)

Example 28 with MimeTypeMap

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;
}
Also used : Request(okhttp3.Request) MimeTypeMap(android.webkit.MimeTypeMap) DownloadManager(android.app.DownloadManager) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 29 with MimeTypeMap

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;
}
Also used : MimeTypeMap(android.webkit.MimeTypeMap)

Example 30 with MimeTypeMap

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);
    }
}
Also used : MimeTypeMap(android.webkit.MimeTypeMap)

Aggregations

MimeTypeMap (android.webkit.MimeTypeMap)51 File (java.io.File)12 Intent (android.content.Intent)7 DownloadManager (android.app.DownloadManager)6 Uri (android.net.Uri)6 IOException (java.io.IOException)4 SimpleDateFormat (java.text.SimpleDateFormat)4 ArrayList (java.util.ArrayList)4 SuppressLint (android.annotation.SuppressLint)3 ActivityNotFoundException (android.content.ActivityNotFoundException)3 ResolveInfo (android.content.pm.ResolveInfo)3 FileNotFoundException (java.io.FileNotFoundException)3 Date (java.util.Date)3 IntentFilter (android.content.IntentFilter)2 Cursor (android.database.Cursor)2 View (android.view.View)2 InputStream (java.io.InputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 MultipartBody (okhttp3.MultipartBody)2