This repository has been archived by the owner on Aug 6, 2022. It is now read-only.
/
DownloadInfo.java
69 lines (60 loc) · 2.61 KB
/
DownloadInfo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright (c) 2015
*
* ApkTrack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ApkTrack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ApkTrack. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.kwiatkowski.apktrack.service.utils;
import android.app.DownloadManager;
import android.content.Context;
import android.database.Cursor;
/**
* This class is used to retrieve the information regarding a downloaded file, based on
* the download ID returned by the the Download Service during the .
*/
public class DownloadInfo
{
public DownloadInfo(long download_id, Context ctx)
{
_download_id = download_id;
DownloadManager dm = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor c = dm.query(new DownloadManager.Query().setFilterById(_download_id));
if (!c.moveToFirst())
{
c.close();
return;
}
_last_modified = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP));
_local_path = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME));
_local_uri = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
_status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
_reason = c.getString(c.getColumnIndex(DownloadManager.COLUMN_REASON));
c.close();
_valid = true;
}
// --------------------------------------------------------------------------------------------
public String get_last_modified() { return _last_modified; }
public String get_local_path() { return _local_path; }
public String get_local_uri() { return _local_uri; }
public int get_status() { return _status; }
public String get_reason() { return _reason; }
public boolean is_valid() { return _valid; }
// --------------------------------------------------------------------------------------------
private String _last_modified;
private String _local_path;
private String _local_uri;
private int _status;
private String _reason;
private long _download_id;
private boolean _valid = false;
}