本文整理汇总了Java中android.app.DownloadManager.Query类的典型用法代码示例。如果您正苦于以下问题:Java Query类的具体用法?Java Query怎么用?Java Query使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Query类属于android.app.DownloadManager包,在下文中一共展示了Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProgressPercentage
import android.app.DownloadManager.Query; //导入依赖的package包/类
private int getProgressPercentage() {
int downloadedBytesSoFar = 0, totalBytes = 0, percentage = 0;
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
try {
Cursor c = dm.query(new DownloadManager.Query().setFilterById(enqueue));
if (c.moveToFirst()) {
int soFarIndex =c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR);
downloadedBytesSoFar = (int) c.getLong(soFarIndex);
int totalSizeIndex = c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES);
totalBytes = (int) c.getLong(totalSizeIndex);
}
System.out.println("PERCEN ------" + downloadedBytesSoFar
+ " ------ " + totalBytes + "****" + percentage);
percentage = (downloadedBytesSoFar * 100 / totalBytes);
System.out.println("percentage % " + percentage);
} catch (Exception e) {
e.printStackTrace();
}
return percentage;
}
示例2: queryDocument
import android.app.DownloadManager.Query; //导入依赖的package包/类
@Override
public Cursor queryDocument(String docId, String[] projection) throws FileNotFoundException {
final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
if (DOC_ID_ROOT.equals(docId)) {
includeDefaultDocument(result);
} else {
// Delegate to real provider
final long token = Binder.clearCallingIdentity();
Cursor cursor = null;
try {
cursor = mDm.query(new Query().setFilterById(Long.parseLong(docId)));
//copyNotificationUri(result, cursor);
if (cursor.moveToFirst()) {
includeDownloadFromCursor(result, cursor);
}
} finally {
IoUtils.closeQuietly(cursor);
Binder.restoreCallingIdentity(token);
}
}
return result;
}
示例3: 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;
}
示例4: queryChildDocumentsForManage
import android.app.DownloadManager.Query; //导入依赖的package包/类
@Override
public Cursor queryChildDocumentsForManage(
String parentDocumentId, 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 {
cursor = mDm.query(
new DownloadManager.Query());//.setOnlyIncludeVisibleInDownloadsUi(true));
//copyNotificationUri(result, cursor);
while (cursor.moveToNext()) {
includeDownloadFromCursor(result, cursor);
}
} finally {
IoUtils.closeQuietly(cursor);
Binder.restoreCallingIdentity(token);
}
return result;
}
示例5: isDownloadComplete
import android.app.DownloadManager.Query; //导入依赖的package包/类
@Override
public synchronized boolean isDownloadComplete(long dmid) {
//Need to check first if the download manager service is enabled
if(!isDownloadManagerEnabled())
return false;
Query query = new Query();
query.setFilterById(dmid);
Cursor c = dm.query(query);
if (c.moveToFirst()) {
int status = c.getInt(c
.getColumnIndex(DownloadManager.COLUMN_STATUS));
c.close();
return (status == DownloadManager.STATUS_SUCCESSFUL);
}
c.close();
return false;
}
示例6: onReceive
import android.app.DownloadManager.Query; //导入依赖的package包/类
@Override
public void onReceive(Context arg0, Intent intent) {
String action = intent.getAction();
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
long downloadId = intent.getLongExtra(
DownloadManager.EXTRA_DOWNLOAD_ID, 0);
Query query = new Query();
query.setFilterById(downloadId);
Cursor c = dm.query(query);
while (c.moveToNext()) {
int columnIndex = c
.getColumnIndex(DownloadManager.COLUMN_STATUS);
if (DownloadManager.STATUS_SUCCESSFUL == c
.getInt(columnIndex)) {
// We've finished all downloads;
stopdownloadbutton.setVisibility(View.GONE);
}
}
}
}
示例7: 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;
}
示例8: onResume
import android.app.DownloadManager.Query; //导入依赖的package包/类
public void onResume() {
super.onResume();
downloadReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
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 columnIndex = c.getColumnIndex(DownloadManager.COLUMN_URI);
String urlDownloaded = c.getString(columnIndex);
if ((issue.getPdfUrl() + "/").equals(urlDownloaded)) {
menu.findItem(R.id.menu_view).setVisible(true);
menu.findItem(R.id.menu_cancel_download).setVisible(false);
}
}
c.close();
}
}
};
getActivity().registerReceiver(downloadReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
示例9: 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);
}
示例10: queryDocument
import android.app.DownloadManager.Query; //导入依赖的package包/类
@Override
public Cursor queryDocument(String docId, String[] projection) throws FileNotFoundException {
final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
if (DOC_ID_ROOT.equals(docId)) {
includeDefaultDocument(result);
} else {
// Delegate to real provider
final long token = Binder.clearCallingIdentity();
Cursor cursor = null;
try {
cursor = mDm.query(new Query().setFilterById(Long.parseLong(docId)));
copyNotificationUri(result, cursor);
if (cursor.moveToFirst()) {
includeTransferFromCursor(result, cursor);
}
} finally {
IoUtils.closeQuietly(cursor);
Binder.restoreCallingIdentity(token);
}
}
return result;
}
示例11: 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 {
cursor = mDm.query(new DownloadManager.Query().setOnlyIncludeVisibleInDownloadsUi(true)
.setFilterByStatus(DownloadManager.STATUS_SUCCESSFUL));
copyNotificationUri(result, cursor);
while (cursor.moveToNext()) {
includeTransferFromCursor(result, cursor);
}
} finally {
IoUtils.closeQuietly(cursor);
Binder.restoreCallingIdentity(token);
}
return result;
}
示例12: queryChildDocumentsForManage
import android.app.DownloadManager.Query; //导入依赖的package包/类
@Override
public Cursor queryChildDocumentsForManage(
String parentDocumentId, 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 {
cursor = mDm.query(
new DownloadManager.Query().setOnlyIncludeVisibleInDownloadsUi(true));
copyNotificationUri(result, cursor);
while (cursor.moveToNext()) {
includeTransferFromCursor(result, cursor);
}
} finally {
IoUtils.closeQuietly(cursor);
Binder.restoreCallingIdentity(token);
}
return result;
}
示例13: queryRecentDocuments
import android.app.DownloadManager.Query; //导入依赖的package包/类
@Override
public Cursor queryRecentDocuments(String rootId, String[] projection)
throws FileNotFoundException {
final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
// Delegate to real provider
final long token = Binder.clearCallingIdentity();
Cursor cursor = null;
try {
cursor = mDm.query(new DownloadManager.Query()//.setOnlyIncludeVisibleInDownloadsUi(true)
.setFilterByStatus(DownloadManager.STATUS_SUCCESSFUL));
//copyNotificationUri(result, cursor);
while (cursor.moveToNext() && result.getCount() < 12) {
final String mimeType = cursor.getString(
cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_MEDIA_TYPE));
final String uri = cursor.getString(
cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_MEDIAPROVIDER_URI));
// Skip images that have been inserted into the MediaStore so we
// don't duplicate them in the recents list.
if (mimeType == null
|| (mimeType.startsWith("image/") && !TextUtils.isEmpty(uri))) {
continue;
}
includeDownloadFromCursor(result, cursor);
}
} finally {
IoUtils.closeQuietly(cursor);
Binder.restoreCallingIdentity(token);
}
return result;
}
示例14: getCompletedDownloadInfo
import android.app.DownloadManager.Query; //导入依赖的package包/类
/**
* Retrieve information about a specific download from DownloadManager.
*/
private static CompletedDownloadInfo getCompletedDownloadInfo(
final DownloadManagerWrapper manager, final long downloadId) {
final Query query = new Query().setFilterById(downloadId);
final Cursor cursor = manager.query(query);
if (null == cursor) {
return new CompletedDownloadInfo(null, downloadId, DownloadManager.STATUS_FAILED);
}
try {
final String uri;
final int status;
if (cursor.moveToNext()) {
final int columnStatus = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
final int columnError = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
final int columnUri = cursor.getColumnIndex(DownloadManager.COLUMN_URI);
final int error = cursor.getInt(columnError);
status = cursor.getInt(columnStatus);
final String uriWithAnchor = cursor.getString(columnUri);
int anchorIndex = uriWithAnchor.indexOf('#');
if (anchorIndex != -1) {
uri = uriWithAnchor.substring(0, anchorIndex);
} else {
uri = uriWithAnchor;
}
if (DownloadManager.STATUS_SUCCESSFUL != status) {
Log.e(TAG, "Permanent failure of download " + downloadId
+ " with error code: " + error);
}
} else {
uri = null;
status = DownloadManager.STATUS_FAILED;
}
return new CompletedDownloadInfo(uri, downloadId, status);
} finally {
cursor.close();
}
}
示例15: run
import android.app.DownloadManager.Query; //导入依赖的package包/类
@Override
public void run() {
try {
final UpdateHelper updateHelper = new UpdateHelper();
final Query query = new Query().setFilterById(mId);
setIndeterminate(true);
while (!isInterrupted()) {
final Cursor cursor = mDownloadManagerWrapper.query(query);
if (null == cursor) {
// Can't contact DownloadManager: this should never happen.
return;
}
try {
if (cursor.moveToNext()) {
final int columnBytesDownloadedSoFar = cursor.getColumnIndex(
DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR);
final int bytesDownloadedSoFar =
cursor.getInt(columnBytesDownloadedSoFar);
updateHelper.setProgressFromAnotherThread(bytesDownloadedSoFar);
} else {
// Download has finished and DownloadManager has already been asked to
// clean up the db entry.
updateHelper.setProgressFromAnotherThread(getMax());
return;
}
} finally {
cursor.close();
}
Thread.sleep(REPORT_PERIOD);
}
} catch (InterruptedException e) {
// Do nothing and terminate normally.
}
}