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