Dahili depolama çalışmalarına yükleme. Ancak, dış sdcard'a indirmeyi denediğimde, durum 2 ~ 3 dakika sonrasına kadar güncellenmez. (İmleç, .getColumnIndex (DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR))) 'dan indirilen 0 bayt aldığım anlamına gelir;). Sonunda 2 ~ 3 dakika sonra indirir.DownloadManager'ı kullanarak harici depolama birimine yükleme işlemi düzgün çalışmıyor Galaxy S7
bildirim durumu da% 0
private void addToDownloadManager(String sourcePath, String destFolder, String deskFileName, DownloadManager downloadManager) {
try {
if(sourcePath == null || sourcePath.equals(""))
return;
try {
File folder = new File(destFolder);
if (!folder.exists()) {
folder.mkdirs();
}
}catch (Exception e) {
}
Uri Download_Uri = Uri.parse(sourcePath);
DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
request.setAllowedOverRoaming(false);
request.setTitle("title");
request.setDescription("description");
File destination = new File(destFolder, deskFileName);
request.setDestinationUri(Uri.fromFile(destination));
downloadReference = downloadManager.enqueue(request);
} catch (Exception e) {
}
}
private Timer mDownloadStatusTimer;
public void downloadStatusTimerSchedule() {
if (mDownloadStatusTimer != null)
downloadStatusTimerCancel();
try {
mDownloadStatusTimer = new Timer("DownloadStatusTimer");
DownloadStatusTimer timer = new DownloadStatusTimer();
mDownloadStatusTimer.schedule(timer, 500, 500); // 0.5 second
} catch (Exception e) {
}
}
public void downloadStatusTimerCancel() {
if (mDownloadStatusTimer != null) {
mDownloadStatusTimer.cancel();
mDownloadStatusTimer.purge();
mDownloadStatusTimer = null;
}
}
private long bytes_downloaded = 0;
private long bytes_total = 0;
public class DownloadStatusTimer extends TimerTask {
@Override
public void run() {
if (mDownloadManager != null) {
DownloadManager.Query myDownloadQuery = new DownloadManager.Query();
Cursor cursor = mDownloadManager.query(myDownloadQuery);
bytes_downloaded = 0;
bytes_total = 0;
try {
if (cursor != null && cursor.moveToFirst()) {
try {
// Get downloaded size/total size
if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_SUCCESSFUL ||
cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_FAILED) {
// do nothing
} else {
bytes_downloaded += cursor.getLong(cursor
.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
bytes_total += cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
}
} catch (Exception e) {
}
while (cursor != null && cursor.moveToNext()) {
try {
// Get downloaded size/total size
if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_SUCCESSFUL ||
cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_FAILED) {
// do nothing
} else {
bytes_downloaded += cursor.getLong(cursor
.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
bytes_total += cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
}
} catch (Exception e) {
}
}
} else {
}
} catch (Exception e) {
} finally {
if (cursor != null) {
cursor.close();
}
}
Log.e("test", "Download size: " + bytes_downloaded + "/" + bytes_total);
MainActivity.this.runOnUiThread(new Runnable() {
public void run() {
try {
tv_download_status.setText("Download size: " + bytes_downloaded + "/" + bytes_total);
} catch (Exception e) {
}
}
});
}
}
}
Ben Not 4 ve Galaxy S5 test edilmiş ve onlar iyi görünüyor diyor.
Android 6.0 olayı olabilir mi? veya S7? Bu bir hata mı? Yoksa burada yanlış yaptığım bir şey var mı? https://drive.google.com/open?id=0By...Ec1ZHk5ZWRkWWc
[Düzenle]
Hedefim: Burada https://drive.google.com/open?id=0BygTefPD845LTkp5QU1mOHRkMDQ
testine APK var:
kendiniz test etmek isterseniz, buraya kaynak koduyla proje konum: /storage/806E-1A11/Android/data/com.joshua.externalsddownloadtest/files/download/video.mp4
bence
File[] files = ContextCompat.getExternalFilesDirs(MainActivity.this, null);
destFolder = null;
for(int i=0; i< files.length; i++) {
if (!files[i].getAbsolutePath().equals(MainActivity.this.getExternalFilesDir(null).getPath())) {
destFolder = files[i].getAbsolutePath();
break;
}
}
boolean bDownloadToExternal = false;
if(destFolder == null) {
tv_download_destination.setText("No external storage found");
} else {
destFolder += "/download/";
tv_download_destination.setText("Destination location: " + destFolder + fileName);
bDownloadToExternal = true;
}
okuyabilir - ne ** tam olarak ** 'hedefin' değeridir? – CommonsWare
@CommonsWare, "Hedef" yolunu ekledim – jclova
'DownloadManager' belki de [çıkarılabilir depolama alanı] üzerinde rasgele noktalara erişim sağlayamıyor (https://commonsware.com/blog/2014/04/09/storage-situation-removable- storage.html) Android 4.4+ üzerinde. Sıradan uygulamalar yok. – CommonsWare