本文整理汇总了Java中android.app.DownloadManager.Query.setFilterByStatus方法的典型用法代码示例。如果您正苦于以下问题:Java Query.setFilterByStatus方法的具体用法?Java Query.setFilterByStatus怎么用?Java Query.setFilterByStatus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.DownloadManager.Query
的用法示例。
在下文中一共展示了Query.setFilterByStatus方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryChildDocuments
import android.app.DownloadManager.Query; //导入方法依赖的package包/类
@Override
public Cursor queryChildDocuments(String docId, String[] projection, String sortOrder)
throws FileNotFoundException {
final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
// Delegate to real provider
final long token = Binder.clearCallingIdentity();
Cursor cursor = null;
try {
Query query = new Query();
DownloadManagerUtils.setOnlyIncludeVisibleInDownloadsUi(query);
//query.setOnlyIncludeVisibleInDownloadsUi(true);
query.setFilterByStatus(DownloadManager.STATUS_SUCCESSFUL);
//query.setFilterByStatus(DownloadManager.STATUS_PENDING | DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_RUNNING | DownloadManager.STATUS_FAILED);
cursor = mDm.query(query);//.setOnlyIncludeVisibleInDownloadsUi(true)
//.setFilterByStatus(DownloadManager.STATUS_SUCCESSFUL));
//copyNotificationUri(result, cursor);
while (cursor.moveToNext()) {
includeDownloadFromCursor(result, cursor);
}
} finally {
IoUtils.closeQuietly(cursor);
Binder.restoreCallingIdentity(token);
}
return result;
}
示例2: getCurrentDownloads
import android.app.DownloadManager.Query; //导入方法依赖的package包/类
public static HashMap<Long,String> getCurrentDownloads(Context ctx) {
HashMap<Long,String> res = new HashMap<Long,String>();
DownloadManager dm = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE);
Query query = new DownloadManager.Query();
if(query!=null)
{
query.setFilterByStatus(DownloadManager.STATUS_FAILED|DownloadManager.STATUS_PAUSED|DownloadManager.STATUS_SUCCESSFUL|
DownloadManager.STATUS_RUNNING|DownloadManager.STATUS_PENDING);
}
Cursor c = dm.query(query);
while (c.moveToNext()) {
int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
if (status == DownloadManager.STATUS_PAUSED ||
status == DownloadManager.STATUS_RUNNING) {
res.put(c.getLong(c.getColumnIndex(DownloadManager.COLUMN_ID)), c.getString(c.getColumnIndex(DownloadManager.COLUMN_TITLE)));
}
}
return res;
}
示例3: cancelDownload
import android.app.DownloadManager.Query; //导入方法依赖的package包/类
private void cancelDownload() {
Query query = new Query();
query.setFilterByStatus(
DownloadManager.STATUS_PAUSED|
DownloadManager.STATUS_PENDING|
DownloadManager.STATUS_RUNNING);
Cursor cur = dm.query(query);
int col = cur.getColumnIndex(DownloadManager.COLUMN_URI);
int colId = cur.getColumnIndex(DownloadManager.COLUMN_ID);
for(cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
if(issue.getPdfUrl().equals(cur.getString(col)))
dm.remove(cur.getLong(colId));
}
cur.close();
menu.findItem(R.id.menu_view).setVisible(true);
menu.findItem(R.id.menu_cancel_download).setVisible(false);
}
示例4: onReceive
import android.app.DownloadManager.Query; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
synchronized (currentDownloads) {
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)
&& !currentDownloads.isEmpty()) {
// long downloadId = intent.getLongExtra(
// DownloadManager.EXTRA_DOWNLOAD_ID, 0);
Query query = new Query();
long[] downloads = new long[currentDownloads.size()];
for (int i = 0, len = currentDownloads.size(); i < len; i++) {
downloads[i] = currentDownloads.get(i);
}
query.setFilterById(downloads);
query.setFilterByStatus(DownloadManager.STATUS_SUCCESSFUL);
Cursor cursor = mDownloadManager.query(query);
boolean pluginAdded = false;
if (cursor.moveToFirst()) {
int columnId = cursor
.getColumnIndex(DownloadManager.COLUMN_ID);
do {
currentDownloads.remove(cursor.getLong(columnId));
pluginAdded = true;
} while (cursor.moveToNext());
if (pluginAdded) {
PluginLoader.reloadPlugins();
}
}
}
}
}
示例5: onReceive
import android.app.DownloadManager.Query; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
Query query = new Query();
query.setFilterByStatus(DownloadManager.STATUS_SUCCESSFUL);
Cursor c = dm.query(query);
if (c.moveToFirst()) {
int titleColumnIndex = c.getColumnIndex(DownloadManager.COLUMN_TITLE);
String title = context.getString(R.string.menu_view) + " " + c.getString(titleColumnIndex);
int pdfPathColumnIndex = c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI);
String pdfPath = c.getString(pdfPathColumnIndex);
Intent intentPdf = new Intent(Intent.ACTION_VIEW);
intentPdf.setDataAndType(Uri.parse(pdfPath), "application/pdf");
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
intentPdf, PendingIntent.FLAG_CANCEL_CURRENT);
SharedPreferences settings = context.getSharedPreferences("IssueDownloadNotification", Context.MODE_PRIVATE);
if(settings.getBoolean(title, false))
return;
settings.edit().putBoolean(title, true).commit();
Notification noti = new NotificationCompat.Builder(context)
.setContentTitle(title)
.setContentText(context.getString(R.string.download_completed_text))
.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.new_issue)
.getNotification();
PebbleNotifier.notify(context, title, context.getString(R.string.download_completed_text));
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(ID_NOTIFICATION++, noti);
}
c.close();
}
}
示例6: listing607
import android.app.DownloadManager.Query; //导入方法依赖的package包/类
private void listing607()
{
/**
* Listing 6-7: Finding details of paused downloads
*/
// Obtain the Download Manager Service.
String serviceString = Context.DOWNLOAD_SERVICE;
DownloadManager downloadManager;
downloadManager = ( DownloadManager ) getSystemService( serviceString );
// Create a query for paused downloads.
Query pausedDownloadQuery = new Query();
pausedDownloadQuery.setFilterByStatus( DownloadManager.STATUS_PAUSED );
// Query the Download Manager for paused downloads.
Cursor pausedDownloads = downloadManager.query( pausedDownloadQuery );
// Find the column indexes for the data we require.
int reasonIdx = pausedDownloads.getColumnIndex( DownloadManager.COLUMN_REASON );
int titleIdx = pausedDownloads.getColumnIndex( DownloadManager.COLUMN_TITLE );
int fileSizeIdx = pausedDownloads.getColumnIndex( DownloadManager.COLUMN_TOTAL_SIZE_BYTES );
int bytesDLIdx = pausedDownloads.getColumnIndex( DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR );
// Iterate over the result Cursor.
while ( pausedDownloads.moveToNext() )
{
// Extract the data we require from the Cursor.
String title = pausedDownloads.getString( titleIdx );
int fileSize = pausedDownloads.getInt( fileSizeIdx );
int bytesDL = pausedDownloads.getInt( bytesDLIdx );
// Translate the pause reason to friendly text.
int reason = pausedDownloads.getInt( reasonIdx );
String reasonString = "Unknown";
switch ( reason )
{
case DownloadManager.PAUSED_QUEUED_FOR_WIFI:
reasonString = "Waiting for WiFi";
break;
case DownloadManager.PAUSED_WAITING_FOR_NETWORK:
reasonString = "Waiting for connectivity";
break;
case DownloadManager.PAUSED_WAITING_TO_RETRY:
reasonString = "Waiting to retry";
break;
default:
break;
}
// Construct a status summary
StringBuilder sb = new StringBuilder();
sb.append( title ).append( "\n" );
sb.append( reasonString ).append( "\n" );
sb.append( "Downloaded " ).append( bytesDL ).append( " / " ).append( fileSize );
// Display the status
Log.d( "DOWNLOAD", sb.toString() );
}
// Close the result Cursor.
pausedDownloads.close();
}