本文整理汇总了Java中android.app.DownloadManager.Request.setNotificationVisibility方法的典型用法代码示例。如果您正苦于以下问题:Java Request.setNotificationVisibility方法的具体用法?Java Request.setNotificationVisibility怎么用?Java Request.setNotificationVisibility使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.DownloadManager.Request
的用法示例。
在下文中一共展示了Request.setNotificationVisibility方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateClientsWithMetadataUri
import android.app.DownloadManager.Request; //导入方法依赖的package包/类
/**
* Download latest metadata from the server through DownloadManager for all relevant clients
*
* @param context The context for retrieving resources
* @param metadataUri The client to update
*/
private static void updateClientsWithMetadataUri(
final Context context, final String metadataUri) {
Log.i(TAG, "updateClientsWithMetadataUri() : MetadataUri = " + metadataUri);
// Adding a disambiguator to circumvent a bug in older versions of DownloadManager.
// DownloadManager also stupidly cuts the extension to replace with its own that it
// gets from the content-type. We need to circumvent this.
final String disambiguator = "#" + System.currentTimeMillis()
+ ApplicationUtils.getVersionName(context) + ".json";
final Request metadataRequest = new Request(Uri.parse(metadataUri + disambiguator));
DebugLogUtils.l("Request =", metadataRequest);
final Resources res = context.getResources();
metadataRequest.setAllowedNetworkTypes(Request.NETWORK_WIFI | Request.NETWORK_MOBILE);
metadataRequest.setTitle(res.getString(R.string.download_description));
// Do not show the notification when downloading the metadata.
metadataRequest.setNotificationVisibility(Request.VISIBILITY_HIDDEN);
metadataRequest.setVisibleInDownloadsUi(
res.getBoolean(R.bool.metadata_downloads_visible_in_download_UI));
final DownloadManagerWrapper manager = new DownloadManagerWrapper(context);
if (maybeCancelUpdateAndReturnIfStillRunning(context, metadataUri, manager,
DictionaryService.NO_CANCEL_DOWNLOAD_PERIOD_MILLIS)) {
// We already have a recent download in progress. Don't register a new download.
return;
}
final long downloadId;
synchronized (sSharedIdProtector) {
downloadId = manager.enqueue(metadataRequest);
DebugLogUtils.l("Metadata download requested with id", downloadId);
// If there is still a download in progress, it's been there for a while and
// there is probably something wrong with download manager. It's best to just
// overwrite the id and request it again. If the old one happens to finish
// anyway, we don't know about its ID any more, so the downloadFinished
// method will ignore it.
writeMetadataDownloadId(context, metadataUri, downloadId);
}
Log.i(TAG, "updateClientsWithMetadataUri() : DownloadId = " + downloadId);
}
示例2: getDownloadListener
import android.app.DownloadManager.Request; //导入方法依赖的package包/类
private DownloadListener getDownloadListener() {
return new DownloadListener() {
public void onDownloadStart(
String url,
String userAgent,
String contentDisposition,
String mimetype,
long contentLength
) {
Uri uri = Uri.parse(url);
Request request = new Request(uri);
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setTitle("File download from Mattermost");
String cookie = CookieManager.getInstance().getCookie(url);
if (cookie != null) {
request.addRequestHeader("cookie", cookie);
}
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
}
};
}
示例3: setupRequest
import android.app.DownloadManager.Request; //导入方法依赖的package包/类
@Override
protected void setupRequest(Request r, Uri uri, String filename) {
super.setupRequest(r, uri, filename);
Log.d("MoodleDownloadHelper", "SR HC");
// When downloading music and videos they will be listed in the player
// (Seems to be available since Honeycomb only)
r.allowScanningByMediaScanner();
// Notify user when download is completed
// (Seems to be available since Honeycomb only)
r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
示例4: manageApiIssues
import android.app.DownloadManager.Request; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static void manageApiIssues(Request request) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
request.setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
} else {
request.setNotificationVisibility(Request.VISIBILITY_VISIBLE);
}
} else
request.setShowRunningNotification(true);
}
示例5: onClick
import android.app.DownloadManager.Request; //导入方法依赖的package包/类
@Override
public void onClick(final View v) {
if (mDownloadUrl == null) {
return;
}
final DownloadManager downloadManager = (DownloadManager)v.getContext().getSystemService(DOWNLOAD_SERVICE);
final Request request = new Request(mDownloadUrl);
request.setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
downloadManager.enqueue(request);
}
示例6: enqueue
import android.app.DownloadManager.Request; //导入方法依赖的package包/类
public void enqueue(DownloadCallback callback) throws IOException {
if (!isExternalStorageWritable()) {
throw new IOException("Cannot write to external storage");
}
Uri source = callback.getSource();
/* Ensure the destination directory already exists. */
File destination = new File(Detlef.getAppContext().getExternalFilesDir(
callback.getDestinationDirType()), callback.getDestinationSubPath());
destination.getParentFile().mkdirs();
Request request = new Request(source);
request.setDestinationInExternalFilesDir(context, callback.getDestinationDirType(),
callback.getDestinationSubPath());
request.addRequestHeader("user-agent", Detlef.USER_AGENT);
request.setTitle(callback.getTitle());
request.setDescription(callback.getDescription());
request.setNotificationVisibility(callback.getNotificationVisibility());
long id = downloadManager.enqueue(request);
activeDownloads.put(id, callback);
callback.onStart(destination.getAbsolutePath());
Log.v(TAG, String.format("Enqueued download with id %d", id));
}
示例7: downloadFfmpeg
import android.app.DownloadManager.Request; //导入方法依赖的package包/类
private void downloadFfmpeg() {
String link = getString(R.string.ffmpeg_download_dialog_msg_link, cpuVers);
Utils.logger("d", "FFmpeg download link: " + link, DEBUG_TAG);
Request request = new Request(Uri.parse(link));
request.setDestinationInExternalFilesDir(nContext, null, ffmpegBinName);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
request.setVisibleInDownloadsUi(false);
request.setTitle(getString(R.string.ffmpeg_download_notification));
dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
try {
enqueue = dm.enqueue(request);
} catch (IllegalArgumentException e) {
Log.e(DEBUG_TAG, "downloadFfmpeg: " + e.getMessage());
Toast.makeText(this, this.getString(R.string.no_downloads_sys_app), Toast.LENGTH_LONG).show();
BugSenseHandler.sendExceptionMessage(DEBUG_TAG + "-> downloadFfmpeg", e.getMessage(), e);
} catch (SecurityException se) {
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, ffmpegBinName);
enqueue = dm.enqueue(request);
DIR = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
BugSenseHandler.sendExceptionMessage(DEBUG_TAG + "-> downloadFfmpeg", se.getMessage(), se);
} catch (NullPointerException ne) {
Log.e(DEBUG_TAG, "callDownloadApk: " + ne.getMessage());
BugSenseHandler.sendExceptionMessage(DEBUG_TAG + "-> callDownloadApk: ", ne.getMessage(), ne);
Toast.makeText(this, getString(R.string.error), Toast.LENGTH_LONG).show();
}
ffmpegBinObserver = new Observer.YtdFileObserver(DIR);
ffmpegBinObserver.startWatching();
}
示例8: setRequestNotificationStatus
import android.app.DownloadManager.Request; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setRequestNotificationStatus(Request request) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
request.setNotificationVisibility(
DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
} else {
request.setShowRunningNotification(true);
}
}
示例9: 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);
}
示例10: execute
import android.app.DownloadManager.Request; //导入方法依赖的package包/类
@Override
public void execute(final Context context) {
if (null == mWordList) { // This should never happen
Log.e(TAG, "UpdateAction with a null parameter!");
return;
}
DebugLogUtils.l("Downloading word list");
final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId);
final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db,
mWordList.mId, mWordList.mVersion);
final int status = values.getAsInteger(MetadataDbHelper.STATUS_COLUMN);
final DownloadManagerWrapper manager = new DownloadManagerWrapper(context);
if (MetadataDbHelper.STATUS_DOWNLOADING == status) {
// The word list is still downloading. Cancel the download and revert the
// word list status to "available".
manager.remove(values.getAsLong(MetadataDbHelper.PENDINGID_COLUMN));
MetadataDbHelper.markEntryAsAvailable(db, mWordList.mId, mWordList.mVersion);
} else if (MetadataDbHelper.STATUS_AVAILABLE != status
&& MetadataDbHelper.STATUS_RETRYING != status) {
// Should never happen
Log.e(TAG, "Unexpected state of the word list '" + mWordList.mId + "' : " + status
+ " for an upgrade action. Fall back to download.");
}
// Download it.
DebugLogUtils.l("Upgrade word list, downloading", mWordList.mRemoteFilename);
// This is an upgraded word list: we should download it.
// Adding a disambiguator to circumvent a bug in older versions of DownloadManager.
// DownloadManager also stupidly cuts the extension to replace with its own that it
// gets from the content-type. We need to circumvent this.
final String disambiguator = "#" + System.currentTimeMillis()
+ ApplicationUtils.getVersionName(context) + ".dict";
final Uri uri = Uri.parse(mWordList.mRemoteFilename + disambiguator);
final Request request = new Request(uri);
final Resources res = context.getResources();
request.setAllowedNetworkTypes(Request.NETWORK_WIFI | Request.NETWORK_MOBILE);
request.setTitle(mWordList.mDescription);
request.setNotificationVisibility(Request.VISIBILITY_HIDDEN);
request.setVisibleInDownloadsUi(
res.getBoolean(R.bool.dict_downloads_visible_in_download_UI));
final long downloadId = UpdateHandler.registerDownloadRequest(manager, request, db,
mWordList.mId, mWordList.mVersion);
Log.i(TAG, String.format("Starting the dictionary download with version:"
+ " %d and Url: %s", mWordList.mVersion, uri));
DebugLogUtils.l("Starting download of", uri, "with id", downloadId);
PrivateLog.log("Starting download of " + uri + ", id : " + downloadId);
}
示例11: 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;
}
示例12: execute
import android.app.DownloadManager.Request; //导入方法依赖的package包/类
@Override
public void execute(final Context context) {
if (null == mWordList) { // This should never happen
Log.e(TAG, "UpdateAction with a null parameter!");
return;
}
Utils.l("Downloading word list");
final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId);
final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db,
mWordList.mId, mWordList.mVersion);
final int status = values.getAsInteger(MetadataDbHelper.STATUS_COLUMN);
final DownloadManager manager =
(DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
if (MetadataDbHelper.STATUS_DOWNLOADING == status) {
// The word list is still downloading. Cancel the download and revert the
// word list status to "available".
if (null != manager) {
// DownloadManager is disabled (or not installed?). We can't cancel - there
// is nothing we can do. We still need to mark the entry as available.
manager.remove(values.getAsLong(MetadataDbHelper.PENDINGID_COLUMN));
}
MetadataDbHelper.markEntryAsAvailable(db, mWordList.mId, mWordList.mVersion);
} else if (MetadataDbHelper.STATUS_AVAILABLE != status) {
// Should never happen
Log.e(TAG, "Unexpected state of the word list '" + mWordList.mId + "' : " + status
+ " for an upgrade action. Fall back to download.");
}
// Download it.
Utils.l("Upgrade word list, downloading", mWordList.mRemoteFilename);
// TODO: if DownloadManager is disabled or not installed, download by ourselves
if (null == manager) return;
// This is an upgraded word list: we should download it.
// Adding a disambiguator to circumvent a bug in older versions of DownloadManager.
// DownloadManager also stupidly cuts the extension to replace with its own that it
// gets from the content-type. We need to circumvent this.
final String disambiguator = "#" + System.currentTimeMillis()
+ com.android.inputmethod.latin.Utils.getVersionName(context) + ".dict";
final Uri uri = Uri.parse(mWordList.mRemoteFilename + disambiguator);
final Request request = new Request(uri);
final Resources res = context.getResources();
if (!mForceStartNow) {
if (DownloadManagerCompatUtils.hasSetAllowedOverMetered()) {
final boolean allowOverMetered;
switch (UpdateHandler.getDownloadOverMeteredSetting(context)) {
case UpdateHandler.DOWNLOAD_OVER_METERED_DISALLOWED:
// User said no: don't allow.
allowOverMetered = false;
break;
case UpdateHandler.DOWNLOAD_OVER_METERED_ALLOWED:
// User said yes: allow.
allowOverMetered = true;
break;
default: // UpdateHandler.DOWNLOAD_OVER_METERED_SETTING_UNKNOWN
// Don't know: use the default value from configuration.
allowOverMetered = res.getBoolean(R.bool.allow_over_metered);
}
DownloadManagerCompatUtils.setAllowedOverMetered(request, allowOverMetered);
} else {
request.setAllowedNetworkTypes(Request.NETWORK_WIFI);
}
request.setAllowedOverRoaming(res.getBoolean(R.bool.allow_over_roaming));
} // if mForceStartNow, then allow all network types and roaming, which is the default.
request.setTitle(mWordList.mDescription);
request.setNotificationVisibility(
res.getBoolean(R.bool.display_notification_for_auto_update)
? Request.VISIBILITY_VISIBLE : Request.VISIBILITY_HIDDEN);
request.setVisibleInDownloadsUi(
res.getBoolean(R.bool.dict_downloads_visible_in_download_UI));
final long downloadId = UpdateHandler.registerDownloadRequest(manager, request, db,
mWordList.mId, mWordList.mVersion);
Utils.l("Starting download of", uri, "with id", downloadId);
PrivateLog.log("Starting download of " + uri + ", id : " + downloadId);
}
示例13: updateClientsWithMetadataUri
import android.app.DownloadManager.Request; //导入方法依赖的package包/类
/**
* Download latest metadata from the server through DownloadManager for all relevant clients
*
* @param context The context for retrieving resources
* @param updateNow Whether we should update NOW, or respect bandwidth policies
* @param metadataUri The client to update
*/
private static void updateClientsWithMetadataUri(final Context context,
final boolean updateNow, final String metadataUri) {
PrivateLog.log("Update for metadata URI " + Utils.s(metadataUri));
// Adding a disambiguator to circumvent a bug in older versions of DownloadManager.
// DownloadManager also stupidly cuts the extension to replace with its own that it
// gets from the content-type. We need to circumvent this.
final String disambiguator = "#" + System.currentTimeMillis()
+ com.android.inputmethod.latin.Utils.getVersionName(context) + ".json";
final Request metadataRequest = new Request(Uri.parse(metadataUri + disambiguator));
Utils.l("Request =", metadataRequest);
final Resources res = context.getResources();
// By default, download over roaming is allowed and all network types are allowed too.
if (!updateNow) {
final boolean allowedOverMetered = res.getBoolean(R.bool.allow_over_metered);
// If we don't have to update NOW, then only do it over non-metered connections.
if (DownloadManagerCompatUtils.hasSetAllowedOverMetered()) {
DownloadManagerCompatUtils.setAllowedOverMetered(metadataRequest,
allowedOverMetered);
} else if (!allowedOverMetered) {
metadataRequest.setAllowedNetworkTypes(Request.NETWORK_WIFI);
}
metadataRequest.setAllowedOverRoaming(res.getBoolean(R.bool.allow_over_roaming));
}
final boolean notificationVisible = updateNow
? res.getBoolean(R.bool.display_notification_for_user_requested_update)
: res.getBoolean(R.bool.display_notification_for_auto_update);
metadataRequest.setTitle(res.getString(R.string.download_description));
metadataRequest.setNotificationVisibility(notificationVisible
? Request.VISIBILITY_VISIBLE : Request.VISIBILITY_HIDDEN);
metadataRequest.setVisibleInDownloadsUi(
res.getBoolean(R.bool.metadata_downloads_visible_in_download_UI));
final DownloadManager manager =
(DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
if (null == manager) {
// Download manager is not installed or disabled.
// TODO: fall back to self-managed download?
return;
}
cancelUpdateWithDownloadManager(context, metadataUri, manager);
final long downloadId;
synchronized (sSharedIdProtector) {
downloadId = manager.enqueue(metadataRequest);
Utils.l("Metadata download requested with id", downloadId);
// If there is already a download in progress, it's been there for a while and
// there is probably something wrong with download manager. It's best to just
// overwrite the id and request it again. If the old one happens to finish
// anyway, we don't know about its ID any more, so the downloadFinished
// method will ignore it.
writeMetadataDownloadId(context, metadataUri, downloadId);
}
PrivateLog.log("Requested download with id " + downloadId);
}