私はアプリケーションを開発しており、Androidのダウンロードマネージャクラスを使用しています。私は "myApp"という名前のフォルダにファイルをダウンロードしたい(フォルダは既に存在する)。これが私が試みたものです。私はまた、ダウンロード場所を設定するさまざまな方法を試みた。しかし、彼らは動作していません。この問題を解決するのを手伝ってください。Androidダウンロードマネージャがファイルのダウンロード場所を設定できないため、実際のファイル名を取得できません
DownloadManager mgr = (DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE);
boolean isDownloading = false;
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterByStatus(
DownloadManager.STATUS_PAUSED|
DownloadManager.STATUS_PENDING|
DownloadManager.STATUS_RUNNING|
DownloadManager.STATUS_SUCCESSFUL
);
Cursor cur = mgr.query(query);
int col = cur.getColumnIndex(
DownloadManager.COLUMN_LOCAL_FILENAME);
for(cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
isDownloading = isDownloading || ("local file path" == cur.getString(col));
}
cur.close();
if (!isDownloading) {
Uri source = Uri.parse(myWebsites[j]);
Uri dst_uri = Uri.parse("file:///mnt/sdcard/Signagee");
DownloadManager.Request request = new DownloadManager.Request(source);
request.setDestinationUri(dst_uri);
request.setNotificationVisibility(
DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED
);
request.allowScanningByMediaScanner();
long id = mgr.enqueue(request);
}
は 'を/ mnt/SDカード/'のようなハードコーディングさパスを使用しないでください。 'Environment'クラスを使用してください –
ファイル名を取得するのに役立ちますか? – venura