0
我想打印成功下載的文件列表,其中列出了下載程序。程序列出3個成功下載的文件。下面的代碼不起作用。代碼已經在模擬器中運行。使用DownloadManager和DownloadManager打印成功下載。查詢
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;
}
}
: - 這段代碼做了什麼? –