本文整理匯總了Java中android.app.DownloadManager.Request.setMimeType方法的典型用法代碼示例。如果您正苦於以下問題:Java Request.setMimeType方法的具體用法?Java Request.setMimeType怎麽用?Java Request.setMimeType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.app.DownloadManager.Request
的用法示例。
在下文中一共展示了Request.setMimeType方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: downloadUri
import android.app.DownloadManager.Request; //導入方法依賴的package包/類
@SuppressWarnings("ResultOfMethodCallIgnored")
public static void downloadUri(
Context context, Uri uri, String fileName, @Nullable String mimeType) {
// Create the destination location
File destination = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS);
destination.mkdirs();
Uri destinationUri = Uri.fromFile(new File(destination, fileName));
// Use the download manager to perform the download
DownloadManager downloadManager =
(DownloadManager) context.getSystemService(Activity.DOWNLOAD_SERVICE);
Request request = new Request(uri)
.setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationUri(destinationUri);
if (mimeType != null) {
request.setMimeType(mimeType);
}
request.allowScanningByMediaScanner();
downloadManager.enqueue(request);
}
示例2: enqueue
import android.app.DownloadManager.Request; //導入方法依賴的package包/類
public long enqueue(String uri, String name, int epi, String vid){
Request request = new Request(Uri.parse(uri));
request.setAllowedNetworkTypes(Request.NETWORK_WIFI);
String externd = uri.substring(uri.lastIndexOf('.'));
String file = name;
String dir = "NetVideo" ;
if(epi != 0){
file += epi;
dir = dir + "/" + name;
}
request.setTitle(file);
request.setDestinationInExternalPublicDir(dir, file + "." + externd);
request.setMimeType("media/video");
request.setDescription(vid);
return mDownloadManager.enqueue(request);
}
示例3: downloadPlugin
import android.app.DownloadManager.Request; //導入方法依賴的package包/類
public static void downloadPlugin(PluginDownloadHolder dataSource) {
Request request = new DownloadManager.Request(
dataSource.getDownloadLink());
request.setDestinationInExternalFilesDir(
GeoARApplication.applicationContext, null,
dataSource.getIdentifier() + ".apk");
request.setTitle("GeoAR Data Souce Download");
request.setMimeType("application/vnd.52north.datasources");
request.setDescription(dataSource.getName());
currentDownloads.add(mDownloadManager.enqueue(request));
}
示例4: downloadFile
import android.app.DownloadManager.Request; //導入方法依賴的package包/類
private void downloadFile() {
// Guess file name from metadata
fileName = URLUtil.guessFileName(downloadUrl, downloadContentDisposition, downloadMimeType);
Request request = new Request(Uri.parse(downloadUrl));
// Make media scanner scan this file so that other apps can use it.
request.allowScanningByMediaScanner();
// show notification when downloading and after download completes
request.setNotificationVisibility(
Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED
);
// Set the directory where to save the file
Log.d("ficsaveM/filePath", Environment.DIRECTORY_DOCUMENTS + "/" + fileName);
request.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOCUMENTS, fileName);
request.setMimeType(downloadMimeType);
request.setTitle(fileName);
// Set headers needed to download the file
String cookies = CookieManager.getInstance().getCookie(downloadUrl);
request.addRequestHeader("cookie", cookies);
request.addRequestHeader("User-Agent", downloadUserAgent);
fileDownloadId = mDownloadManager.enqueue(request);
Log.d("ficsaveM/DownloadStartd", "fileID: " + fileDownloadId + ", fileName: " + fileName);
Toast.makeText(mContext, R.string.downloading_file_toast_msg, //To notify the Client that the file is being downloaded
Toast.LENGTH_LONG).show();
mGTracker.send(new HitBuilders.EventBuilder()
.setCategory(DOWNLOAD_LISTENER_CATEGORY)
.setAction("Download Enqueued")
.setLabel(FILE_LABEL + fileName)
.setValue(1)
.build());
Bundle bundle = new Bundle();
bundle.putString("File", fileName);
mFTracker.logEvent("DownloadEnqueued", bundle);
}
示例5: run
import android.app.DownloadManager.Request; //導入方法依賴的package包/類
@Override
public Void run(JobContext jc) {
try {
if (checkDownloadRunning())
return null;
if (checkApkExist()) {
Intent installApkIntent = new Intent();
installApkIntent.setAction(Intent.ACTION_VIEW);
installApkIntent.setDataAndType(
Uri.parse(Preferences.getDownloadPath(mContext)),
"application/vnd.android.package-archive");
installApkIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
mContext.startActivity(installApkIntent);
} else {
String apkName = mContext.getPackageName()
+ System.currentTimeMillis() + Constants.APK_SUFFIX;
// 係統下載程序
final DownloadManager downloadManager = (DownloadManager) mContext
.getSystemService(mContext.DOWNLOAD_SERVICE);
Long recommendedMaxBytes = DownloadManager
.getRecommendedMaxBytesOverMobile(mContext);
// 可以在移動網絡下下載
if (recommendedMaxBytes == null
|| recommendedMaxBytes.longValue() > MAX_ALLOWED_DOWNLOAD_BYTES_BY_MOBILE) {
allowMobileDownload = true;
}
Uri uri = Uri.parse(mUpgradeInfo.getUrl());
final Request request = new Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
int NETWORK_TYPE = DownloadManager.Request.NETWORK_WIFI;
if (allowMobileDownload) {
NETWORK_TYPE |= DownloadManager.Request.NETWORK_MOBILE;
}
request.setAllowedNetworkTypes(NETWORK_TYPE);
request.allowScanningByMediaScanner();
request.setShowRunningNotification(true);
request.setVisibleInDownloadsUi(true);
request.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS, apkName);
PackageManager packageManager = mContext.getPackageManager();
ApplicationInfo applicationInfo = packageManager
.getApplicationInfo(mContext.getPackageName(), 0);
Log.i("liweiping",
"appName = "
+ packageManager
.getApplicationLabel(applicationInfo));
request.setTitle(packageManager
.getApplicationLabel(applicationInfo));
request.setMimeType("application/vnd.android.package-archive");
// id 保存起來跟之後的廣播接收器作對比
long id = downloadManager.enqueue(request);
long oldId = Preferences.getDownloadId(mContext);
if (oldId != -1) {
downloadManager.remove(oldId);
}
Preferences.removeAll(mContext);
Preferences.setDownloadId(mContext, id);
Preferences.setUpgradeInfo(mContext, mUpgradeInfo);
Preferences.setDownloadStatus(mContext,
Constants.DOWNLOAD_STATUS_RUNNING);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}