我想打印下载程序列出的成功下载文件列表。下载程序列出了 3 个已成功下载的文件。下面的代码不起作用。代码已在模拟器中运行。
package com.talespinkit.downloadinfodeleter;
import android.app.DownloadManager;
import android.app.DownloadManager.Query;
import android.database.Cursor;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
private static final String TAG = "MainActivity";
private DownloadManager downloadManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
}
@Override
protected void onResume() {
super.onResume();
Query q = new Query();
q.setFilterByStatus(DownloadManager.STATUS_SUCCESSFUL);
Cursor cursor = downloadManager.query(q);
Log.d(TAG, String.valueOf(cursor.getCount())); // prints 0
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { // Does not enters this loop
Log.d(TAG, String.valueOf(cursor.getColumnCount()));
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}