admin
2021-07-28 c0269fcfa876b9c5cf309b2006462b4d09c5ef95
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
package com.hanju.video.app.util;
 
import android.content.Context;
import android.database.Cursor;
 
import com.mozillaonline.providers.DownloadManager;
import com.hanju.video.app.db.DownloadTable;
 
public class DownloadUtils {
 
    public static String getOfflinePath(Context context, String videoId,
            String videoDetailId) {
        String offlinePath = null;
        Cursor downloadCursor = context.getContentResolver().query(
                DownloadTable.CONTENT_URI,
                null,
                DownloadTable.VIDEO_ID + " = ? AND "
                        + DownloadTable.VIDEO_DETAIL_ID + " = ? ",
                new String[] { videoId, videoDetailId }, null);
        if (downloadCursor.moveToFirst()) {
            DownloadManager downloadManager = new DownloadManager(
                    context.getContentResolver(), context.getPackageName());
            downloadManager.setAccessAllDownloads(true);
            DownloadManager.Query baseQuery = new DownloadManager.Query()
                    .setOnlyIncludeVisibleInDownloadsUi(true);
            baseQuery.setFilterById(downloadCursor.getLong(downloadCursor
                    .getColumnIndex(DownloadTable.TASK_ID)));
            Cursor c = downloadManager.query(baseQuery);
            if (c.moveToFirst()) {
                int status = c.getInt(c
                        .getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS));
                if (status == DownloadManager.STATUS_SUCCESSFUL) {
                    offlinePath = c
                            .getString(c
                                    .getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI));
                }
            }
            c.close();
        }
        downloadCursor.close();
        return offlinePath;
    }
 
    public static boolean isOffline(Context context, String videoId,
            String videoDetailId) {
        Cursor downloadCursor = context.getContentResolver().query(
                DownloadTable.CONTENT_URI,
                null,
                DownloadTable.VIDEO_ID + " = ? AND "
                        + DownloadTable.VIDEO_DETAIL_ID + " = ? ",
                new String[] { videoId, videoDetailId }, null);
        if (downloadCursor.moveToFirst()) {
            return true;
        }
        downloadCursor.close();
        return false;
    }
 
    public static String getSaveDir(Context context) {
 
        return null;
    }
}