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


Java URLUtil.guessFileName方法代码示例

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


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

示例1: downloadFile

import android.webkit.URLUtil; //导入方法依赖的package包/类
@AfterPermissionGranted(WRITE_EXTERNAL_REQUEST_CODE)
public void downloadFile(String url, String userAgent, String contentDisposition, String mimetype) {
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    request.setMimeType(mimetype);
    cookieManager = CookieManager.getInstance();
    PersistentConfig persistentConfig = new PersistentConfig(activity.getApplicationContext());
    persistentConfig.setCookie(getCookies(Session.getSession(activity.getApplicationContext())));
    cookieManager.setCookie(host, persistentConfig.getCookieString());
    request.addRequestHeader("Cookie", getCookies(Session.getSession(activity.getApplicationContext())));
    request.setDescription("Downloading file...");
    request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimetype));
    request.allowScanningByMediaScanner();
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype);
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
    DownloadManager dManager = (DownloadManager) getActivity().getSystemService(DOWNLOAD_SERVICE);
    dManager.enqueue(request);
}
 
开发者ID:active-citizen,项目名称:android.java,代码行数:19,代码来源:WebShopFragment.java

示例2: guessImageFormatC

import android.webkit.URLUtil; //导入方法依赖的package包/类
@SuppressLint("NewApi")
public static CompressFormat guessImageFormatC(String urlOrPath) {
    CompressFormat format = null;
    String fileName;
    if (URLUtil.isNetworkUrl(urlOrPath)) {
        fileName = URLUtil.guessFileName(urlOrPath, null, null);
    } else if (urlOrPath.lastIndexOf('.') <= 0) {
        return null;
    } else {
        fileName = urlOrPath;
    }
    fileName = fileName.toLowerCase(Locale.US);
    if (fileName.endsWith(".png")) {
        format = CompressFormat.PNG;
    } else if (fileName.endsWith(".jpg") || fileName.endsWith(".jpeg")) {
        format = CompressFormat.JPEG;
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && fileName.endsWith(".webp")) {
        format = CompressFormat.WEBP;
    }
    return format;
}
 
开发者ID:WeiChou,项目名称:Wei.Lib2A,代码行数:22,代码来源:BitmapUtils.java

示例3: onDownloadStart

import android.webkit.URLUtil; //导入方法依赖的package包/类
@Override
public void onDownloadStart(final String url, final String userAgent, final String contentDisposition, final String mimetype, long contentLength) {
    String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype);
    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch (which) {
                case DialogInterface.BUTTON_POSITIVE:
                    WebDownLoadHandler.downLoad(mActivity, url, PreferencesUtil.getInstance(mActivity).getString(Constants.SP_WEB_DOWN_PATH), userAgent, contentDisposition, mimetype);
                    break;

                case DialogInterface.BUTTON_NEGATIVE:
                    break;
            }
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); // dialog
    builder.setTitle(fileName)
            .setMessage("开始download")
            .setPositiveButton("begin",
                    dialogClickListener)
            .setNegativeButton("cancel",
                    dialogClickListener).show();
}
 
开发者ID:liftting,项目名称:android-mine-core,代码行数:26,代码来源:WebDownLoadListener.java

示例4: getMediafilename

import android.webkit.URLUtil; //导入方法依赖的package包/类
public String getMediafilename(FeedMedia media) {
    String filename;
    String titleBaseFilename = "";

    // Try to generate the filename by the item title
    if (media.getItem() != null && media.getItem().getTitle() != null) {
        String title = media.getItem().getTitle();
        // Delete reserved characters
        titleBaseFilename = title.replaceAll("[\\\\/%\\?\\*:|<>\"\\p{Cntrl}]", "");
        titleBaseFilename = titleBaseFilename.trim();
    }

    String URLBaseFilename = URLUtil.guessFileName(media.getDownload_url(),
            null, media.getMime_type());
    ;

    if (titleBaseFilename != "") {
        // Append extension
        filename = titleBaseFilename + FilenameUtils.EXTENSION_SEPARATOR +
                FilenameUtils.getExtension(URLBaseFilename);
    } else {
        // Fall back on URL file name
        filename = URLBaseFilename;
    }
    return filename;
}
 
开发者ID:danieloeh,项目名称:AntennaPodSP,代码行数:27,代码来源:DownloadRequester.java

示例5: download

import android.webkit.URLUtil; //导入方法依赖的package包/类
/**
 * Download PDF from param URL and save it in folder /directory_name/
 * If a PDF with the URL already exists then open it instead.
 * @param url the URL to the file which should be downloaded.
 * @param viewPDF true when the file should be displayed directly after downloading.
 * @param showProcess true when a dialog should show the process. Otherwise do in background.
 */
public File download(String url, boolean viewPDF, boolean showProcess)
{
    String fileExtenstion = MimeTypeMap.getFileExtensionFromUrl(url);
    String fileName = URLUtil.guessFileName(url, null, fileExtenstion);
    File pdfFile = new File(Environment.getExternalStorageDirectory() + "/" + directory_name + "/" + fileName);
    if (pdfFile.exists() && viewPDF) {
        view(fileName);
    } else if (!pdfFile.exists() && isNetworkAvailable()) {
        new DownloadFile(showProcess).execute(url, fileName);
    } else if (!isNetworkAvailable() && !pdfFile.exists()) {
        Toast.makeText(getActivity(), getResources().getString(R.string.no_connecting), Toast.LENGTH_SHORT).show();
        pdfFile = null;
    }
    return pdfFile;
}
 
开发者ID:maksim-m,项目名称:KitAlumniApp-Client,代码行数:23,代码来源:KitAtAGlanceFragment.java

示例6: downloadFile

import android.webkit.URLUtil; //导入方法依赖的package包/类
public static void downloadFile(final Activity activity, final String url,
		final String userAgent, final String contentDisposition, final boolean privateBrowsing) {
	String fileName = URLUtil.guessFileName(url, null, null);
	DownloadHandler.onDownloadStart(activity, url, userAgent, contentDisposition, null,
			privateBrowsing);
	Log.i(Constants.TAG, "Downloading" + fileName);
}
 
开发者ID:NewCasino,项目名称:browser,代码行数:8,代码来源:Utils.java

示例7: onDownloadStart

import android.webkit.URLUtil; //导入方法依赖的package包/类
@Override
public void onDownloadStart(final String url, final String userAgent,
		final String contentDisposition, final String mimetype, long contentLength) {
	String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype);
	DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
		@Override
		public void onClick(DialogInterface dialog, int which) {
			switch (which) {
				case DialogInterface.BUTTON_POSITIVE:
					DownloadHandler.onDownloadStart(mActivity, url, userAgent,
							contentDisposition, mimetype, false);
					break;

				case DialogInterface.BUTTON_NEGATIVE:
					break;
			}
		}
	};

	AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); // dialog
	builder.setTitle(fileName)
			.setMessage(mActivity.getResources().getString(R.string.dialog_download))
			.setPositiveButton(mActivity.getResources().getString(R.string.action_download),
					dialogClickListener)
			.setNegativeButton(mActivity.getResources().getString(R.string.action_cancel),
					dialogClickListener).show();
	Log.i(Constants.TAG, "Downloading" + fileName);

}
 
开发者ID:NewCasino,项目名称:browser,代码行数:30,代码来源:LightningDownloadListener.java

示例8: downloadOMAContent

import android.webkit.URLUtil; //导入方法依赖的package包/类
/**
 * Enqueue a download request to the DownloadManager and starts downloading the OMA content.
 *
 * @param downloadId The unique identifier maintained by the Android DownloadManager.
 * @param downloadInfo Information about the download.
 * @param omaInfo Information about the OMA content.
 */
private void downloadOMAContent(long downloadId, DownloadInfo downloadInfo, OMAInfo omaInfo) {
    if (omaInfo == null) return;
    String mimeType = omaInfo.getDrmType();
    if (mimeType == null) {
        mimeType = getOpennableType(mContext.getPackageManager(), omaInfo);
    }
    String fileName = omaInfo.getValue(OMA_NAME);
    String url = omaInfo.getValue(OMA_OBJECT_URI);
    if (TextUtils.isEmpty(fileName)) {
        fileName = URLUtil.guessFileName(url, null, mimeType);
    }
    DownloadInfo newInfo = DownloadInfo.Builder.fromDownloadInfo(downloadInfo)
            .setFileName(fileName)
            .setUrl(url)
            .setMimeType(mimeType)
            .setDescription(omaInfo.getValue(OMA_DESCRIPTION))
            .setContentLength(getSize(omaInfo))
            .build();
    // If installNotifyURI is not empty, the downloaded content cannot
    // be used until the PostStatusTask gets a 200-series response.
    // Don't show complete notification until that happens.
    DownloadItem item = new DownloadItem(true, newInfo);
    item.setSystemDownloadId(downloadId);
    DownloadManagerService.getDownloadManagerService(mContext).enqueueDownloadManagerRequest(
            item, omaInfo.isValueEmpty(OMA_INSTALL_NOTIFY_URI));
    mPendingOMADownloads.put(downloadId, omaInfo);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:35,代码来源:OMADownloadHandler.java

示例9: shouldInterceptContextMenuDownload

import android.webkit.URLUtil; //导入方法依赖的package包/类
/**
 * For certain download types(OMA for example), android DownloadManager should
 * handle them. Call this function to intercept those downloads.
 *
 * @param url URL to be downloaded.
 * @return whether the DownloadManager should intercept the download.
 */
public boolean shouldInterceptContextMenuDownload(String url) {
    Uri uri = Uri.parse(url);
    String scheme = uri.normalizeScheme().getScheme();
    if (!"http".equals(scheme) && !"https".equals(scheme)) return false;
    String path = uri.getPath();
    // OMA downloads have extension "dm" or "dd". For the latter, it
    // can be handled when native download completes.
    if (path == null || !path.endsWith(".dm")) return false;
    if (mTab == null) return true;
    String fileName = URLUtil.guessFileName(
            url, null, OMADownloadHandler.OMA_DRM_MESSAGE_MIME);
    final DownloadInfo downloadInfo =
            new DownloadInfo.Builder().setUrl(url).setFileName(fileName).build();
    WindowAndroid window = mTab.getWindowAndroid();
    if (window.hasPermission(permission.WRITE_EXTERNAL_STORAGE)) {
        onDownloadStartNoStream(downloadInfo);
    } else if (window.canRequestPermission(permission.WRITE_EXTERNAL_STORAGE)) {
        PermissionCallback permissionCallback = new PermissionCallback() {
            @Override
            public void onRequestPermissionsResult(
                    String[] permissions, int[] grantResults) {
                if (grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    onDownloadStartNoStream(downloadInfo);
                }
            }
        };
        window.requestPermissions(
                new String[] {permission.WRITE_EXTERNAL_STORAGE}, permissionCallback);
    }
    return true;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:40,代码来源:ChromeDownloadDelegate.java

示例10: displaySnackbar

import android.webkit.URLUtil; //导入方法依赖的package包/类
private void displaySnackbar(final Context context, long completedDownloadReference, DownloadManager downloadManager) {
    if (!isFocusDownload(completedDownloadReference)) {
        return;
    }

    final DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterById(completedDownloadReference);
    try (Cursor cursor = downloadManager.query(query)) {
        if (cursor.moveToFirst()) {
            int statusColumnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
            if (DownloadManager.STATUS_SUCCESSFUL == cursor.getInt(statusColumnIndex)) {
                String uriString = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));

                final String localUri = uriString.startsWith(FILE_SCHEME) ? uriString.substring(FILE_SCHEME.length()) : uriString;
                final String fileExtension = MimeTypeMap.getFileExtensionFromUrl(localUri);
                final String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension);
                final String fileName = URLUtil.guessFileName(Uri.decode(localUri), null, mimeType);

                final File file = new File(Uri.decode(localUri));
                final Uri uriForFile = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + FILE_PROVIDER_EXTENSION, file);
                final Intent openFileIntent = IntentUtils.createOpenFileIntent(uriForFile, mimeType);
                showSnackbarForFilename(openFileIntent, context, fileName);
            }
        }
    }
    removeFromHashSet(completedDownloadReference);
}
 
开发者ID:mozilla-mobile,项目名称:focus-android,代码行数:28,代码来源:DownloadBroadcastReceiver.java

示例11: getDefaultSavedPath

import android.webkit.URLUtil; //导入方法依赖的package包/类
/**
 * 默认保存到download/retrofit文件夹下
 * @return
 */
private String getDefaultSavedPath() {
    String fileName =  URLUtil.guessFileName(url,"","");
    if(TextUtils.isEmpty(fileName)){
        fileName = UUID.randomUUID().toString();
    }else {
        //android 系统,不允许文件名中有冒号
        fileName = fileName.replace("?","-");
        fileName = fileName.replace(":","-");
        fileName = fileName.replace(":","-");
    }

   File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),"httputil");
    if(!dir.exists()){
      boolean success =   dir.mkdirs();
        MyLog.e("dirs create success:"+success +"--"+dir.getAbsolutePath());
    }
    File file = new File(dir,fileName);
    /*if(file.exists()){
        file.delete();
    }else {
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }*/

    return file.getAbsolutePath();
}
 
开发者ID:hss01248,项目名称:HttpUtilForAndroid,代码行数:34,代码来源:DownloadBuilder.java

示例12: copyCacheFileToDir

import android.webkit.URLUtil; //导入方法依赖的package包/类
/**
 * 拷贝到某一个目录中,自动命名
 * @param url
 * @param dir
 * @return
 */
public static File copyCacheFileToDir(String url,File dir){

    if (dir == null ){
        return null;
    }
    if (!dir.isDirectory()){
        throw  new RuntimeException(dir + "is not a directory,you should call copyCacheFile(String url,File path)");
    }
    if (!dir.exists()){
        dir.mkdirs();
    }
    String fileName = URLUtil.guessFileName(url,"","");//android SDK 提供的方法.
    // 注意不能直接采用file的getName拿到文件名,因为缓存文件是用cacheKey命名的
    if (TextUtils.isEmpty(fileName)){
        fileName = UUID.randomUUID().toString();
    }
    File newFile = new File(dir,fileName);

    boolean isSuccess =  copyCacheFile(url,newFile);
    if (isSuccess){
        return newFile;
    }else {
        return null;
    }

}
 
开发者ID:glassLake,项目名称:fastDev,代码行数:33,代码来源:FrescoUtils.java

示例13: copyCacheFileToDir

import android.webkit.URLUtil; //导入方法依赖的package包/类
/**
 * 拷贝到某一个目录中,自动命名
 * @param url
 * @param dir
 * @return
 */
public static File copyCacheFileToDir(String url,File dir){
    url = append(url);
    if (dir == null ){
        return null;
    }
    if (!dir.isDirectory()){
        throw  new RuntimeException(dir + "is not a directory,you should call copyCacheFile(String url,File path)");
    }
    if (!dir.exists()){
        dir.mkdirs();
    }
    String fileName = URLUtil.guessFileName(url,"","");//android SDK 提供的方法.
    // 注意不能直接采用file的getName拿到文件名,因为缓存文件是用cacheKey命名的
    if (TextUtils.isEmpty(fileName)){
        fileName = UUID.randomUUID().toString();
    }
    File newFile = new File(dir,fileName);

   boolean isSuccess =  copyCacheFile(url,newFile);
    if (isSuccess){
        return newFile;
    }else {
        return null;
    }

}
 
开发者ID:hss01248,项目名称:MyImageUtil,代码行数:33,代码来源:FrescoUtil.java

示例14: downloadFile

import android.webkit.URLUtil; //导入方法依赖的package包/类
/**
 * Download file
 *
 * @param url
 * @param contentDisposition
 * @param mimeType
 */
private void downloadFile(String url, String contentDisposition, String mimeType) {
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    String filename = URLUtil.guessFileName(url, contentDisposition, mimeType);
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
    DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    dm.enqueue(request);
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("*/*");
    Toast.makeText(MainActivity.this, "Downloading: " + filename, Toast.LENGTH_SHORT).show();
}
 
开发者ID:RiccardoBusetti,项目名称:Colombo,代码行数:20,代码来源:MainActivity.java

示例15: copyCacheFileToDir

import android.webkit.URLUtil; //导入方法依赖的package包/类
/**
 * 拷贝到某一个目录中,自动命名
 * @param url
 * @param dir
 * @return
 */
public static File copyCacheFileToDir(String url,File dir){

    if (dir == null ){
        return null;
    }
    if (!dir.isDirectory()){
        throw  new RuntimeException(dir + "is not a directory,you should call copyCacheFile(String url,File path)");
    }
    if (!dir.exists()){
        dir.mkdirs();
    }
    String fileName = URLUtil.guessFileName(url,"","");//android SDK 提供的方法.
    // 注意不能直接采用file的getName拿到文件名,因为缓存文件是用cacheKey命名的
    if (TextUtils.isEmpty(fileName)){
        fileName = UUID.randomUUID().toString();
    }
    File newFile = new File(dir,fileName);

   boolean isSuccess =  copyCacheFile(url,newFile);
    if (isSuccess){
        return newFile;
    }else {
        return null;
    }

}
 
开发者ID:glassLake,项目名称:FrescoUtlis,代码行数:33,代码来源:FrescoUtils.java


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