Java Code Examples for android.webkit.MimeTypeMap#getFileExtensionFromUrl()
The following examples show how to use
android.webkit.MimeTypeMap#getFileExtensionFromUrl() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: react-native-GPay File: BlobModule.java License: MIT License | 6 votes |
private String getMimeTypeFromUri(Uri contentUri) { String type = getReactApplicationContext().getContentResolver().getType(contentUri); if (type == null) { String ext = MimeTypeMap.getFileExtensionFromUrl(contentUri.getPath()); if (ext != null) { type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext); } } if (type == null) { type = ""; } return type; }
Example 2
Source Project: traccar-manager-android File: MainFragment.java License: Apache License 2.0 | 6 votes |
public String getMimeType(String url) { String extension = MimeTypeMap.getFileExtensionFromUrl(url); if (extension != null) { switch (extension) { case "js": return "text/javascript"; case "woff": return "application/font-woff"; case "woff2": return "application/font-woff2"; case "ttf": return "application/x-font-ttf"; case "eot": return "application/vnd.ms-fontobject"; case "svg": return "image/svg+xml"; default: return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); } } return null; }
Example 3
Source Project: react-native-doc-viewer File: RNDocViewerModule.java License: MIT License | 6 votes |
/** * Returns the MIME Type of the file by looking at file name extension in * the URL. * * @param url * @return */ private static String getMimeType(String url) { String mimeType = null; System.out.println("Url: " + url); url = url.replaceAll(" ", ""); String extension = MimeTypeMap.getFileExtensionFromUrl(url); if (extension != null) { mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); } if (mimeType == null) { mimeType = "application/pdf"; System.out.println("Mime Type (default): " + mimeType); } return mimeType; }
Example 4
Source Project: simple_share File: FileHelper.java License: MIT License | 5 votes |
private String getMimeType(String url) { String type = null; String extension = MimeTypeMap.getFileExtensionFromUrl(url); if (extension != null) { type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); } return type; }
Example 5
Source Project: OpenHub File: GitHubHelper.java License: GNU General Public License v3.0 | 5 votes |
public static boolean isArchive(@Nullable String name) { if (StringUtils.isBlank(name)) return false; name = name.toLowerCase(); for (String value : ARCHIVE_EXTENSIONS) { String extension = MimeTypeMap.getFileExtensionFromUrl(name); if ((extension != null && value.replace(".", "").equals(extension)) || name.endsWith(value)) return true; } return false; }
Example 6
Source Project: fdroidclient File: BluetoothServer.java License: GNU General Public License v3.0 | 5 votes |
public static String getMimeTypeForFile(String uri) { String type = null; String extension = MimeTypeMap.getFileExtensionFromUrl(uri); if (extension != null) { MimeTypeMap mime = MimeTypeMap.getSingleton(); type = mime.getMimeTypeFromExtension(extension); } return type; }
Example 7
Source Project: sandriosCamera File: Utils.java License: MIT License | 5 votes |
public static String getMimeType(String url) { String type = ""; String extension = MimeTypeMap.getFileExtensionFromUrl(url); if (!TextUtils.isEmpty(extension)) { type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); } else { String reCheckExtension = MimeTypeMap.getFileExtensionFromUrl(url.replaceAll("\\s+", "")); if (!TextUtils.isEmpty(reCheckExtension)) { type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(reCheckExtension); } } return type; }
Example 8
Source Project: SimplicityBrowser File: Helpers.java License: MIT License | 5 votes |
public static String getMimeType(String url) { String extension = MimeTypeMap.getFileExtensionFromUrl(url); if (extension != null) { return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); } return null; }
Example 9
Source Project: PowerFileExplorer File: StreamSource.java License: GNU General Public License v3.0 | 5 votes |
public StreamSource(SmbFile file,long l) throws SmbException { fp = 0; len = l; mime = MimeTypeMap.getFileExtensionFromUrl(file.getName()); name = file.getName(); this.file = file; bufferSize = 1024*60; }
Example 10
Source Project: LiveSourceCode File: FileBinary.java License: Apache License 2.0 | 5 votes |
@Override public String mimeType() { String type = "application/octet-stream"; String name = file.getName(); // 判断文件是否有扩展名,有则根据扩展名拿到type。 if (MimeTypeMap.getSingleton().hasExtension(name)) { String extension = MimeTypeMap.getFileExtensionFromUrl(name); return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); } return type; }
Example 11
Source Project: AdBlockedWebView-Android File: FileUtils.java License: MIT License | 5 votes |
public static long downloadFile(Context context, String url, String mimeType) { try { String[] fnm = url.split("/"); String fileName = fnm[fnm.length - 1]; fileName = getFileName(fileName); String host = fnm[2]; String extension = MimeTypeMap.getFileExtensionFromUrl(url); if(extension.equals("")) extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType); String fileNameWithExtension = fileName + "." + extension; DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); Uri uri = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(uri); request.setTitle(fileNameWithExtension); request.setMimeType(mimeType); request.setDescription(host); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileNameWithExtension); File downloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); if (!downloadsDir.exists()) { //noinspection ResultOfMethodCallIgnored downloadsDir.mkdirs(); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); } else { //noinspection deprecation request.setShowRunningNotification(true); } request.setVisibleInDownloadsUi(true); long downloadId = dm.enqueue(request); Toast.makeText(context, context.getString(R.string.message_download_started), Toast.LENGTH_SHORT).show(); return downloadId; } catch (SecurityException e) { throw new SecurityException("No permission allowed: android.permission.WRITE_EXTERNAL_STORAGE"); } }
Example 12
Source Project: react-native-share File: ShareFiles.java License: MIT License | 5 votes |
/** * Obtain mime type from URL * @param url {@link String} * @return {@link String} mime type */ private String getMimeType(String url) { String type = null; String extension = MimeTypeMap.getFileExtensionFromUrl(url); if (extension != null) { type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); } return type; }
Example 13
Source Project: GSYVideoPlayer File: ProxyCacheUtils.java License: Apache License 2.0 | 4 votes |
static String getSupposablyMime(String url) { MimeTypeMap mimes = MimeTypeMap.getSingleton(); String extension = MimeTypeMap.getFileExtensionFromUrl(url); return TextUtils.isEmpty(extension) ? null : mimes.getMimeTypeFromExtension(extension); }
Example 14
Source Project: AndroidVideoCache File: ProxyCacheUtils.java License: Apache License 2.0 | 4 votes |
static String getSupposablyMime(String url) { MimeTypeMap mimes = MimeTypeMap.getSingleton(); String extension = MimeTypeMap.getFileExtensionFromUrl(url); return TextUtils.isEmpty(extension) ? null : mimes.getMimeTypeFromExtension(extension); }
Example 15
Source Project: pandora File: FileUtil.java License: Apache License 2.0 | 4 votes |
public static String getFileType(String filePath) { String ext = MimeTypeMap.getFileExtensionFromUrl(filePath); return MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext); }
Example 16
Source Project: openlauncher File: ContextUtils.java License: Apache License 2.0 | 4 votes |
/** * Detect MimeType of given file * Android/Java's own MimeType map is very very small and detection barely works at all * Hence use custom map for some file extensions */ public String getMimeType(final Uri uri) { String mimeType = null; if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) { ContentResolver cr = _context.getContentResolver(); mimeType = cr.getType(uri); } else { String ext = MimeTypeMap.getFileExtensionFromUrl(uri.toString()); mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext.toLowerCase()); // Try to guess if the recommended methods fail if (TextUtils.isEmpty(mimeType)) { switch (ext) { case "md": case "markdown": case "mkd": case "mdown": case "mkdn": case "mdwn": case "rmd": mimeType = "text/markdown"; break; case "yaml": case "yml": mimeType = "text/yaml"; break; case "json": mimeType = "text/json"; break; case "txt": mimeType = "text/plain"; break; } } } if (TextUtils.isEmpty(mimeType)) { mimeType = "*/*"; } return mimeType; }
Example 17
Source Project: OpenHub File: GitHubHelper.java License: GNU General Public License v3.0 | 4 votes |
public static String getExtension(@Nullable String name) { if (StringUtils.isBlank(name)) return null; return MimeTypeMap.getFileExtensionFromUrl(name); }
Example 18
Source Project: WliveTV File: BaseImageDownloader.java License: Apache License 2.0 | 4 votes |
private boolean isVideoFileUri(String uri) { String extension = MimeTypeMap.getFileExtensionFromUrl(uri); String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); return mimeType != null && mimeType.startsWith("video/"); }
Example 19
Source Project: android-imageviewer File: ImageViewerActivity.java License: Apache License 2.0 | 4 votes |
public void initData() { imageLoader = ImageLoader.getInstance(); imageUrls = new ArrayList<String>(); Intent intent = getIntent(); if (intent != null) { Bundle bundle = intent.getExtras(); if (bundle != null) { imageUrls = bundle.getStringArrayList(Extra.IMAGES); imagePosition = bundle.getInt(Extra.IMAGE_POSITION, 0); imageMode = bundle.getInt(Extra.IMAGE_MODE, 0); Log.i("The snowdream bundle path of the image is: " + imageUri); } Uri uri = (Uri) intent.getData(); if (uri != null) { imageUri = uri.getPath(); fileName = uri.getLastPathSegment(); getSupportActionBar().setSubtitle(fileName); Log.i("The path of the image is: " + imageUri); File file = new File(imageUri); imageUri = "file://" + imageUri; File dir = file.getParentFile(); if (dir != null) { FileFilter fileFilter = new FileFilter() { @Override public boolean accept(File f) { if (f != null) { String extension = MimeTypeMap.getFileExtensionFromUrl(Uri.encode(f.getAbsolutePath())); if (!TextUtils.isEmpty(extension)) { String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); if (!TextUtils.isEmpty(mimeType) && mimeType.contains("image")) { return true; } } } return false; } } ; File[] files = dir.listFiles(fileFilter); if (files != null && files.length > 0) { int size = files.length; for (int i = 0; i < size; i++) { imageUrls.add("file://" + files[i].getAbsolutePath()); } imagePosition = imageUrls.indexOf(imageUri); imageMode = 1; Log.i("Image Position:" + imagePosition); } } else { imageUrls.add("file://" + imageUri); imagePosition = 0; imageMode = 0; } } } else { Log.w("The intent is null!"); } }
Example 20
Source Project: AndServer File: MediaType.java License: Apache License 2.0 | 2 votes |
/** * Get he extension by url. * * @param url url. * * @return extension name. */ public static String getUrlExtension(String url) { String extension = MimeTypeMap.getFileExtensionFromUrl(url); return TextUtils.isEmpty(extension) ? "" : extension; }