List of usage examples for android.webkit MimeTypeMap getFileExtensionFromUrl
public static String getFileExtensionFromUrl(String url)
From source file:com.google.android.apps.forscience.whistlepunk.PictureUtils.java
public static void launchExternalViewer(Activity activity, String fileUrl) { Intent intent = new Intent(Intent.ACTION_VIEW); String extension = MimeTypeMap.getFileExtensionFromUrl(fileUrl); String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); if (!TextUtils.isEmpty(type)) { String filePath = fileUrl; if (filePath.startsWith("file:")) { filePath = filePath.substring("file:".length()); }//w w w . j ava2 s . co m Uri photoUri = FileProvider.getUriForFile(activity, activity.getPackageName(), new File(filePath)); intent.setDataAndType(photoUri, type); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // Needed to avoid security exception on KitKat. intent.setClipData(ClipData.newRawUri(null, photoUri)); } intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); try { activity.startActivity(intent); } catch (ActivityNotFoundException e) { Log.e(TAG, "No activity found to handle this " + fileUrl + " type " + type); } } else { Log.w(TAG, "Could not find mime type for " + fileUrl); } }
From source file:org.odk.collect.android.widgets.ArbitraryFileWidget.java
public String getMimeType(String url) { String extension = MimeTypeMap.getFileExtensionFromUrl(url); return extension != null ? MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) : null; }
From source file:com.hippo.nimingban.ui.GalleryActivity2.java
/** * @param uri the save image file url, null for fail * @param share true for share//ww w . j a v a 2 s.co m */ public void onSaveTaskOver(Uri uri, boolean share) { if (mSaveTask != null) { mSaveTask = null; } if (share) { if (uri == null) { Toast.makeText(this, R.string.cant_save_image, Toast.LENGTH_SHORT).show(); } else { String mimeType = getContentResolver().getType(uri); if (TextUtils.isEmpty(mimeType)) { mimeType = MimeTypeMap.getSingleton() .getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(uri.toString())); if (TextUtils.isEmpty(mimeType)) { mimeType = "image/*"; } } Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_STREAM, uri); intent.setType(mimeType); startActivity(Intent.createChooser(intent, getString(R.string.share_image))); } } else { Toast.makeText(this, uri != null ? R.string.save_successfully : R.string.save_failed, Toast.LENGTH_SHORT).show(); } }
From source file:com.owncloud.android.utils.BitmapUtils.java
/** * Checks if file passed is an image/* w ww . j av a 2s . c o m*/ * @param file * @return true/false */ public static boolean isImage(File file) { final Uri selectedUri = Uri.fromFile(file); final String fileExtension = MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString().toLowerCase()); final String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension); return (mimeType != null && mimeType.startsWith("image/")); }
From source file:bg.fourweb.android.rss.RssHandler.java
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { super.startElement(uri, localName, qName, attributes); checkStopCondition();/*w ww . j a va 2s. c o m*/ boolean createValueB = false; currentElt = elements.containsKey(localName) ? elements.get(localName) : ELT_INVALID; // @formatter:off switch (currentElt) { // case ELT_CHANNEL: inChannel = true; break; case ELT_ITEM: inItems = true; currentItemB = new ItemBuilder(); break; case ELT_IMAGE: inImage = true; break; // channel // --- // tags that contain value only case ELT_TITLE: // channel & image & item case ELT_LINK: // channel & image & item case ELT_DESCRIPTION: // channel & item case ELT_LANGUAGE: // channel case ELT_COPYRIGHT: // channel case ELT_MANAGINGEDITOR: // channel case ELT_WEBMASTER: // channel case ELT_PUBDATE: // channel & item case ELT_LASTBUILDDATE: // channel case ELT_GENERATOR: // channel case ELT_DOCS: // channel case ELT_CLOUD: // channel case ELT_TTL: // channel case ELT_IMAGE_URL: // image case ELT_IMAGE_WIDTH: // image case ELT_IMAGE_HEIGHT: // image case ELT_RATING: // channel case ELT_SKIPHOURS: // channel case ELT_SKIPDAYS: // channel case ELT_AUTHOR: // item case ELT_COMMENTS: // item createValueB = true; break; // --- // tags that contain both values and attributes case ELT_CATEGORY: categoryDomain = attributes.getValue("domain"); createValueB = true; break; // channel & item case ELT_GUID: currentItemB.guidIsPermaLink(attributes.getValue("isPermaLink")); createValueB = true; break; // item case ELT_SOURCE: currentItemB.sourceUrl(attributes.getValue("url")); createValueB = true; break; // item // --- // tags that contain attributes only case ELT_ENCLOSURE: {// item final String url = attributes.getValue("url"); int length; try { length = Integer.parseInt(attributes.getValue("length")); } catch (NumberFormatException e) { length = 0; } final String mimeType = attributes.getValue("type"); currentItemB.addEnclosureUrl(url, length, mimeType); break; } case ELT_THUMBNAIL: { final String url = attributes.getValue("url"); final String mimeType = StringUtils.isEmpty(url) ? "" : MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(url)); int width; try { width = Integer.parseInt(attributes.getValue("width")); } catch (NumberFormatException e) { width = 0; } int height; try { height = Integer.parseInt(attributes.getValue("height")); } catch (NumberFormatException e) { height = 0; } final Thumbnail t = new Thumbnail(url, mimeType, width, height); if (largestThumbnail == null || largestThumbnail.compareTo(t) < 0) { largestThumbnail = t; } } } // @formatter:on if (createValueB) { valueB = new StringBuilder(63); } }
From source file:com.laurencedawson.image_management.ImageManager.java
/** * Given an image URL, check if the cached image is a GIF * @param url The URL of the image/*w w w .j ava 2 s . c o m*/ * @return True if the image is a GIF */ public boolean isGif(String url) { if (url == null) { return false; } // First try to grab the mime from the options Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(getFullCacheFileName(mContext, url), options); if (options.outMimeType != null && options.outMimeType.equals(ImageManager.GIF_MIME)) { return true; } // Next, try to grab the mime type from the url final String extension = MimeTypeMap.getFileExtensionFromUrl(url); if (extension != null) { String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); if (mimeType != null) { return mimeType.equals(ImageManager.GIF_MIME); } } return false; }
From source file:com.owncloud.android.utils.MimeTypeUtil.java
/** * Extracts the mime type for the given file. * * @param file the file to be analyzed//from ww w . j a va 2 s.c om * @return the file's mime type */ private static String extractMimeType(File file) { Uri selectedUri = Uri.fromFile(file); String fileExtension = MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString().toLowerCase(Locale.ROOT)); return MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension); }
From source file:com.nbplus.hybrid.BasicWebViewClient.java
public String getMimeType(String url) { String type = null;//from w w w . java2 s.c o m String extension = MimeTypeMap.getFileExtensionFromUrl(url); if (extension != null) { type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); } return type; }
From source file:com.orange.ocara.ui.activity.ListAuditActivity.java
@Receiver(actions = AuditExportService.EXPORT_SUCCESS, local = true, registerAt = Receiver.RegisterAt.OnResumeOnPause) @UiThread(propagation = UiThread.Propagation.REUSE) void onExportAuditDone(@Receiver.Extra String path) { setLoading(false);//ww w . j ava 2 s .co m exportFile = new File(path); switch (exportAction) { case EXPORT_ACTION_SHARE: { // create an intent, so the user can choose which application he/she wants to use to share this file final Intent intent = ShareCompat.IntentBuilder.from(this) .setType(MimeTypeMap.getSingleton() .getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(path))) .setStream(FileProvider.getUriForFile(this, "com.orange.ocara", exportFile)) .setChooserTitle("How do you want to share?").createChooserIntent() .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(intent); break; } case EXPORT_ACTION_SAVE: { createNewDocument(path); break; } } }
From source file:com.orange.ocara.ui.activity.ListAuditActivity.java
private void createNewDocument(String path) { Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType(//from www.jav a2 s . c om MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(path))); startActivityForResult(intent, ACTION_CREATE_NEW_DOCUMENT); }