Java Code Examples for android.app.DownloadManager.Query#setFilterByStatus()

The following examples show how to use android.app.DownloadManager.Query#setFilterByStatus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadStorageProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: DownloadStorageProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: DownloadStorageProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 4
Source File: IssueDetailsFragment.java    From magpi-android with MIT License 6 votes vote down vote up
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));
}
 
Example 5
Source File: IssueDetailsFragment.java    From magpi-android with MIT License 6 votes vote down vote up
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);
}
 
Example 6
Source File: PluginDownloader.java    From geoar-app with Apache License 2.0 5 votes vote down vote up
@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();
				}
			}

		}
	}
}
 
Example 7
Source File: DownloadCompletedReceiver.java    From magpi-android with MIT License 5 votes vote down vote up
@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();
       }
}