当前位置: 首页>>代码示例>>Java>>正文


Java MimeTypeMap.getFileExtensionFromUrl方法代码示例

本文整理汇总了Java中android.webkit.MimeTypeMap.getFileExtensionFromUrl方法的典型用法代码示例。如果您正苦于以下问题:Java MimeTypeMap.getFileExtensionFromUrl方法的具体用法?Java MimeTypeMap.getFileExtensionFromUrl怎么用?Java MimeTypeMap.getFileExtensionFromUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.webkit.MimeTypeMap的用法示例。


在下文中一共展示了MimeTypeMap.getFileExtensionFromUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldOverrideUrlLoading

import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
@Override
public boolean shouldOverrideUrlLoading(XWalkView view, String url) {
    if (!(url.startsWith("http") || url.startsWith("https"))) {
        //非http https协议 不动作
        return true;
    }

    //http https协议 在本webView中加载

    String extension = MimeTypeMap.getFileExtensionFromUrl(url);
    if(VideoFormatUtil.containsVideoExtension(extension)){
        detectedTaskUrlQueue.add(new DetectedVideoInfo(url,currentUrl,currentTitle));
        Log.d("MainActivity", "shouldOverrideUrlLoading detectTaskUrlList.add(url):" + url);
        return true;
    }

    Log.d("MainActivity", "shouldOverrideUrlLoading url="+url);
    view.loadUrl(url);
    return true;
}
 
开发者ID:xm0625,项目名称:VBrowser-Android,代码行数:21,代码来源:MainActivity.java

示例2: testQueryActionViewIntentActivities

import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
@Test
public void testQueryActionViewIntentActivities() throws Exception {
    File txt = new File("/test.txt");
    Uri uri = Uri.fromFile(txt);
    // 获取扩展名
    String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString());
    // 获取MimeType
    String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
    // 创建隐式Intent
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, mimeType);

    Context context = InstrumentationRegistry.getContext();
    PackageManager packageManager = context.getPackageManager();
    // 根据Intent查询匹配的Activity列表
    List<ResolveInfo> resolvers =
            packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

    for (ResolveInfo resolver : resolvers) {
        Log.d(TAG, resolver.activityInfo.packageName + "\n" + resolver.activityInfo.name);
    }
}
 
开发者ID:JulianAndroid,项目名称:AppChooser,代码行数:23,代码来源:ResolversRepositoryTest.java

示例3: getMimeType

import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
/**
 * To find out the extension of required object in given uri
 * Solution by http://stackoverflow.com/a/36514823/1171484
 */
public static String getMimeType(Activity context, Uri uri) {
    String extension;
    //Check uri format to avoid null
    if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
        //If scheme is a content
        extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(context.getContentResolver().getType(uri));
        if (TextUtils.isEmpty(extension))extension=MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(new File(uri.getPath())).toString());
    } else {
        //If scheme is a File
        //This will replace white spaces with %20 and also other special characters. This will avoid returning null values on file name with spaces and special characters.
        extension = MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(new File(uri.getPath())).toString());
        if (TextUtils.isEmpty(extension))extension=MimeTypeMap.getSingleton().getExtensionFromMimeType(context.getContentResolver().getType(uri));
    }
    if(TextUtils.isEmpty(extension)){
        extension=getMimeTypeByFileName(TUriParse.getFileWithUri(uri,context).getName());
    }
    return extension;
}
 
开发者ID:duckitgo,项目名称:DigPhotoPicker,代码行数:23,代码来源:TImageFiles.java

示例4: recordSaveLinkTypes

import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
/**
 * Records the content types when user downloads the file by long pressing the
 * save link context menu option.
 */
static void recordSaveLinkTypes(String url) {
    String extension = MimeTypeMap.getFileExtensionFromUrl(url);
    int mimeType = TYPE_UNKNOWN;
    if (extension != null) {
        String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        if (type != null) {
            if (type.startsWith("text")) {
                mimeType = TYPE_TEXT;
            } else if (type.startsWith("image")) {
                mimeType = TYPE_IMAGE;
            } else if (type.startsWith("audio")) {
                mimeType = TYPE_AUDIO;
            } else if (type.startsWith("video")) {
                mimeType = TYPE_VIDEO;
            } else if (type.equals("application/pdf")) {
                mimeType = TYPE_PDF;
            }
        }
    }
    RecordHistogram.recordEnumeratedHistogram(
            "ContextMenu.SaveLinkType", mimeType, NUM_TYPES);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:27,代码来源:ChromeContextMenuPopulator.java

示例5: isImage

import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
public static boolean isImage(@Nullable String name) {
    if (InputHelper.isEmpty(name)) return false;
    name = name.toLowerCase();
    for (String value : IMAGE_EXTENSIONS) {
        String extension = MimeTypeMap.getFileExtensionFromUrl(name);
        if ((extension != null && value.replace(".", "").equals(extension)) || name.endsWith(value)) return true;
    }
    return false;
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:10,代码来源:MarkDownProvider.java

示例6: linkTo

import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
@Override
public boolean linkTo(@NonNull final String url, final String target)
{
	// if url is handled by client, return query to client, which will handle it by initiating another query
	if (this.urlScheme != null && url.startsWith(this.urlScheme))
	{
		final String source2 = url.substring(this.urlScheme.length());
		requery(source2);
		return true;
	}

	// standard handling
	try
	{
		final Intent intent = new Intent(Intent.ACTION_VIEW);
		final Uri uri = Uri.parse(url);
		final String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString());
		final String mimetype = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
		if (mimetype == null)
		{
			intent.setData(uri);
		}
		else
		{
			intent.setDataAndType(uri, mimetype);
		}
		startActivity(intent);
		return true;
	}
	catch (@NonNull final Exception ignored)
	{
		Toast.makeText(this, R.string.error_link, Toast.LENGTH_LONG).show();
	}
	return false;
}
 
开发者ID:1313ou,项目名称:Treebolic,代码行数:36,代码来源:TreebolicBasicActivity.java

示例7: getMimeType

import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
public static String getMimeType(String url){
    String type = null;
    String extension = MimeTypeMap.getFileExtensionFromUrl(url);
    if (extension != null) {
        MimeTypeMap mime = MimeTypeMap.getSingleton();
        type = mime.getMimeTypeFromExtension(extension);
    }
    return type;
}
 
开发者ID:PlutoArchitecture,项目名称:Pluto-Android,代码行数:10,代码来源:BitmapUtil.java

示例8: isImage

import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
public static boolean isImage(@Nullable String name) {
    if (StringUtils.isBlank(name)) return false;
    name = name.toLowerCase();
    for (String value : IMAGE_EXTENSIONS) {
        String extension = MimeTypeMap.getFileExtensionFromUrl(name);
        if ((extension != null && value.replace(".", "").equals(extension))
                || name.endsWith(value))
            return true;
    }
    return false;
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:12,代码来源:GitHubHelper.java

示例9: getType

import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
@Override
public String getType(Uri uri) {
    String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString().toLowerCase(Locale.ROOT));
    String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
    if (TextUtils.isEmpty(mimeType)) {
        mimeType = "application/octet-stream";
    }
    return mimeType;
}
 
开发者ID:dbrant,项目名称:zimdroid,代码行数:10,代码来源:ZimContentProvider.java

示例10: openFile

import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
private void openFile(String filePath) {
    Uri uri = FileProvider.getUriForFile(getActivity(),
            BuildConfig.APPLICATION_ID + ".provider",
            new File(filePath));

    String fileExtension = MimeTypeMap.getFileExtensionFromUrl(uri.toString());
    String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension
            (fileExtension);

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, mimeType);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    startActivity(Intent.createChooser(intent, getString(R.string.open_file)));
}
 
开发者ID:metarhia,项目名称:metacom-android,代码行数:15,代码来源:FilesFragment.java

示例11: getExtension

import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
public static String getExtension(String filename){
	String extension = MimeTypeMap.getFileExtensionFromUrl(filename);
	if (TextUtils.isEmpty(extension)) {
		/*
		 * getFileExtensionFromUrl doesn't work for files with
		 * spaces
		 */
		int dotIndex = filename.lastIndexOf('.');
		if (dotIndex >= 0) {
			extension = filename.substring(dotIndex + 1);
		}
	}
	return extension;
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:15,代码来源:MimeManagement.java

示例12: getMimeType

import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
public static @Nullable String getMimeType(Context context, Uri uri) {
  if (uri == null) return null;

  if (PersistentBlobProvider.isAuthority(context, uri)) {
    return PersistentBlobProvider.getMimeType(context, uri);
  }

  String type = context.getContentResolver().getType(uri);
  if (type == null) {
    final String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString());
    type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.toLowerCase());
  }
  return getCorrectedMimeType(type);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:15,代码来源:MediaUtil.java

示例13: getMimeType

import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
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;
}
 
开发者ID:MartinRGB,项目名称:android_camera_experiment,代码行数:14,代码来源:Utils.java

示例14: isMarkdown

import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
public static boolean isMarkdown(@Nullable String name) {
    if (StringUtils.isBlank(name)) return false;
    name = name.toLowerCase();
    for (String value : MARKDOWN_EXTENSIONS) {
        String extension = MimeTypeMap.getFileExtensionFromUrl(name);
        if ((extension != null && value.replace(".", "").equals(extension)) ||
                name.equalsIgnoreCase("README") || name.endsWith(value))
            return true;
    }
    return false;
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:12,代码来源:GitHubHelper.java

示例15: isPdfDownload

import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
@Override
public boolean isPdfDownload(String url) {
    String fileExtension = MimeTypeMap.getFileExtensionFromUrl(url);
    if (TextUtils.isEmpty(fileExtension)) return false;

    return PDF_EXTENSION.equals(fileExtension);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:8,代码来源:ExternalNavigationDelegateImpl.java


注:本文中的android.webkit.MimeTypeMap.getFileExtensionFromUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。