本文整理匯總了Java中android.os.Environment.DIRECTORY_DOWNLOADS屬性的典型用法代碼示例。如果您正苦於以下問題:Java Environment.DIRECTORY_DOWNLOADS屬性的具體用法?Java Environment.DIRECTORY_DOWNLOADS怎麽用?Java Environment.DIRECTORY_DOWNLOADS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.os.Environment
的用法示例。
在下文中一共展示了Environment.DIRECTORY_DOWNLOADS屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDestinationDirectory
private static File getDestinationDirectory(Context context, int destination, boolean running)
throws IOException {
switch (destination) {
case Downloads.Impl.DESTINATION_CACHE_PARTITION:
case Downloads.Impl.DESTINATION_CACHE_PARTITION_PURGEABLE:
case Downloads.Impl.DESTINATION_CACHE_PARTITION_NOROAMING:
if (running) {
return context.getFilesDir();
} else {
return context.getCacheDir();
}
case Downloads.Impl.DESTINATION_EXTERNAL:
final File target = new File(
Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DOWNLOADS);
if (!target.isDirectory() && target.mkdirs()) {
throw new IOException("unable to create external downloads directory");
}
return target;
default:
throw new IllegalStateException("unexpected destination: " + destination);
}
}
示例2: startDownload
private void startDownload() {
Snackbar.make(activity.findViewById(R.id.fragment_container), "Downloading started.", Snackbar.LENGTH_SHORT).show();
String path = Environment.getExternalStorageDirectory().toString() + File.separator +
Environment.DIRECTORY_DOWNLOADS + File.separator + "wulkanowy";
File dir = new File(path);
if(!dir.mkdirs()) {
for (String aChildren : dir.list()) {
new File(dir, aChildren).delete();
}
}
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(update.getUrlToDownload().toString()))
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false)
.setTitle("Wulkanowy v" + update.getLatestVersionCode())
.setDescription(update.getLatestVersion())
.setVisibleInDownloadsUi(true)
.setMimeType("application/vnd.android.package-archive")
.setDestinationUri(Uri.fromFile(new File(path + File.separator + update.getLatestVersion() + ".apk")));
downloadManager.enqueue(request);
}
示例3: dirChecker
private static void dirChecker(String dir) {
File f = new File(Environment.DIRECTORY_DOWNLOADS + dir);
if(!f.isDirectory()) {
f.mkdirs();
}
}
示例4: getDownloadDir
public static File getDownloadDir() throws NoExternalStorageException {
return new File(getSignalStorageDir(), Environment.DIRECTORY_DOWNLOADS);
}
示例5: onClick
@Override
public void onClick(View v) {
if (v.getId() == R.id.download) {
checkPermiss();
if (isDownloading) {
Toast.makeText(MainActivity.this, "心急吃不了豆腐", Toast.LENGTH_SHORT).show();
return;
}
DownloadManager.Request request = new DownloadManager.Request(Uri.parse("http://download.taobaocdn.com/wireless/taobao4android/latest/701483.apk"));
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
request.setTitle("下載jpg");
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
request.setMimeType("image/jpeg");
//實際下載後存放的路徑並不一定是這個名字,如果有重名的,自動向名字中追加數字編號
File apkFile = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DOWNLOADS + "/701483.apk");
request.setDestinationUri(Uri.fromFile(apkFile));
downloadId = dw.enqueue(request);
isDownloading = true;
Uri uri = dw.getDownloadUri(downloadId);
if (uri != null) {
progressBar.setMax(1000);
progressBar.setProgress(0);
if (observer != null) {
getContentResolver().unregisterContentObserver(observer);
observer = null;
}
observer = new DownloadStatusObserver();
getContentResolver().registerContentObserver(uri, true, observer);
}
} else if (v.getId() == R.id.pause) {
dw.pauseDownload(downloadId);
} else if (v.getId() == R.id.resume) {
dw.resumeDownload(downloadId);
}
}