PlaceHolder使用Android下载管理器下载失败的原因

时间:2015-07-21 13:59:46

标签: android android-activity

我正在使用下载管理器下载类型(.mov,.pdf,.png)文件。当我调用下载管理器时,下载失败并给出了作为占位符的原因。占位符是什么意思,我该如何解决这个问题?请帮忙!

我的代码如下:

DownloadManager.Request request = new DownloadManager.Request(Uri.parse(downloadUrlFile))
    .setDestinationInExternalFilesDir(context,
        (Environment.DIRECTORY_DOWNLOADS), downloadFileName).setNotificationVisibility(visibility);

mEnqueue = downloadManager.enqueue(request);
mDownloadReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "DOWNLOAD_STATUS"+intent.getAction());
        String action = intent.getAction();
        if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
            Query query = new Query();
            query.setFilterById(mEnqueue);
            Cursor c = downloadManager.query(query);
            if (c.moveToFirst()) {
                int columnIndex = c            .getColumnIndex(DownloadManager.COLUMN_STATUS);
                Log.d("getColumnIndex()", "Reason: " + c
                        .getColumnIndex(DownloadManager.COLUMN_STATUS)+DownloadManager.STATUS_SUCCESSFUL);
                if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
                    Log.d(TAG, "DOWNLOAD_STATUS_SUCCESSFUL");
                } else if (DownloadManager.STATUS_FAILED == c.getInt(columnIndex)) {
                    Log.d("handleData()", "Reason: " + c.getString(c.getColumnIndex(DownloadManager.COLUMN_REASON)));
                    Log.d(TAG, "DOWNLOAD_STATUS_FAILED");
                } 
            } 
        } 
    } 
};

1 个答案:

答案 0 :(得分:3)

问题是该列" COLUMN_REASON"是一个int而不是一个String(尽管我已经看到一些例子,暗示它是一个字符串)。

因此你应该使用:

Log.d("handleData()", "Reason: " + c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON)));

可以找到该值: Herehere