當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。