当前位置: 首页>>代码示例>>Java>>正文


Java Query.setFilterById方法代码示例

本文整理汇总了Java中android.app.DownloadManager.Query.setFilterById方法的典型用法代码示例。如果您正苦于以下问题:Java Query.setFilterById方法的具体用法?Java Query.setFilterById怎么用?Java Query.setFilterById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.DownloadManager.Query的用法示例。


在下文中一共展示了Query.setFilterById方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:edx,项目名称:edx-app-android,代码行数:22,代码来源:IDownloadManagerImpl.java

示例2: 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);					
			}
		}
	}
}
 
开发者ID:conchyliculture,项目名称:wikipoff,代码行数:23,代码来源:WikiAvailableActivity.java

示例3: getDownload

import android.app.DownloadManager.Query; //导入方法依赖的package包/类
@Override
public synchronized  NativeDownloadModel getDownload(long dmid) {
    //Need to check first if the download manager service is enabled
    if(!isDownloadManagerEnabled())
        return null;

    try {
        Query query = new Query();
        query.setFilterById(dmid);

        Cursor c = dm.query(query);
        if (c.moveToFirst()) {
            long downloaded = c
                    .getLong(c
                            .getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
            long size = c.getLong(c
                    .getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
            String filepath = c.getString(c
                    .getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME));
            int status = c.getInt(c
                    .getColumnIndex(DownloadManager.COLUMN_STATUS));

            c.close();
            
            NativeDownloadModel ndm = new NativeDownloadModel();
            ndm.dmid = dmid;
            ndm.downloaded = downloaded;
            ndm.size = size;
            ndm.filepath = filepath;
            ndm.status = status;
            
            return ndm;
        }
        c.close();
    } catch(Exception e) {
        logger.error(e);
    }
    return null;
}
 
开发者ID:edx,项目名称:edx-app-android,代码行数:40,代码来源:IDownloadManagerImpl.java

示例4: getAverageProgressForDownloads

import android.app.DownloadManager.Query; //导入方法依赖的package包/类
@Override
public synchronized int getAverageProgressForDownloads(long[] dmids) {
    //Need to check first if the download manager service is enabled
    if(!isDownloadManagerEnabled())
        return 0;

    Query query = new Query();
    query.setFilterById(dmids);
    try {
        Cursor c = dm.query(query);
        if (c.moveToFirst()) {
            int count = c.getCount();
            float aggrPercent = 0;
            do {
                long downloaded = c
                    .getLong(c
                        .getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
                long size = c.getLong(c
                    .getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));

                aggrPercent += (100f * downloaded / size);
            } while (c.moveToNext());

            c.close();

            int average = (int) (aggrPercent / count);
            return average;
        }
        c.close();
    }catch (Exception ex){
        logger.debug(ex.getMessage());
    }
    
    return 0;
}
 
开发者ID:edx,项目名称:edx-app-android,代码行数:36,代码来源:IDownloadManagerImpl.java

示例5: 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();
				}
			}

		}
	}
}
 
开发者ID:52North,项目名称:geoar-app,代码行数:34,代码来源:PluginDownloader.java

示例6: downloadCompleted

import android.app.DownloadManager.Query; //导入方法依赖的package包/类
private void downloadCompleted(Context context, Intent intent) {
    //Files are  ready
    String filename = context.getString(R.string.hs_attachment);
    String filepath = null;
    String mediaType = null;
    DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
    StringBuilder text = new StringBuilder();

    Query query = new Query();
    query.setFilterById(downloadId);
    Cursor c = dm.query(query);
    if (c.moveToFirst()) {
        int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
        filename = c.getString(c.getColumnIndex(DownloadManager.COLUMN_TITLE));
        filepath = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
        mediaType = c.getString(c.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE));
        if (status == DownloadManager.STATUS_SUCCESSFUL) {
            text.append(context.getString(R.string.hs_download_complete));
        } else {
            text.append(context.getString(R.string.hs_error_during_download));
        }
    }

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
    notificationBuilder.setAutoCancel(true);
    notificationBuilder.setContentText(text.toString());
    notificationBuilder.setContentTitle(filename);
    notificationBuilder.setSmallIcon(R.drawable.hs_download_light);
    notificationBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
    notificationBuilder.setContentIntent(getPendingIntent(context));

    notificationManager.notify(filename, NOTIFICATION_ID, notificationBuilder.build());
}
 
开发者ID:happyfoxinc,项目名称:helpstack-android,代码行数:37,代码来源:AttachmentDownloadReceiver.java

示例7: onCreate

import android.app.DownloadManager.Query; //导入方法依赖的package包/类
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);

	BroadcastReceiver receiver = new BroadcastReceiver() {
		@Override
		public void onReceive(Context context, Intent intent) {
			String action = intent.getAction();
			if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
				long downloadId = intent.getLongExtra(
						DownloadManager.EXTRA_DOWNLOAD_ID, 0);
				Query query = new Query();
				query.setFilterById(enqueue);
				Cursor c = dm.query(query);
				if (c.moveToFirst()) {
					int columnIndex = c
							.getColumnIndex(DownloadManager.COLUMN_STATUS);
					if (DownloadManager.STATUS_SUCCESSFUL == c
							.getInt(columnIndex)) {

						ImageView view = (ImageView) findViewById(R.id.imageView1);
						String uriString = c
								.getString(c
										.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
						view.setImageURI(Uri.parse(uriString));
					}
				}
			}
		}
	};

	registerReceiver(receiver, new IntentFilter(
			DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
 
开发者ID:vogellacompany,项目名称:codeexamples-android,代码行数:37,代码来源:DownloadManagerActivity.java

示例8: getDownloadQueryAsInt

import android.app.DownloadManager.Query; //导入方法依赖的package包/类
private int getDownloadQueryAsInt(long id, String column) {
    Query query = new Query();
    query.setFilterById(id);

    Cursor c = downloadManager.query(query);
    if (!c.moveToFirst()) {
        return -1;
    }

    int columnIndex = c.getColumnIndex(column);
    return c.getInt(columnIndex);
}
 
开发者ID:gpodder,项目名称:detlef,代码行数:13,代码来源:DetlefDownloadManager.java

示例9: listing604

import android.app.DownloadManager.Query; //导入方法依赖的package包/类
private void listing604()
{
    final DownloadManager downloadManager = ( DownloadManager ) getSystemService( Context.DOWNLOAD_SERVICE );

    /**
     * Listing 6-4: Monitoring downloads for completion
     */
    IntentFilter filter = new IntentFilter( DownloadManager.ACTION_DOWNLOAD_COMPLETE );

    BroadcastReceiver receiver = new BroadcastReceiver()
    {
        @Override
        public void onReceive( Context context, Intent intent )
        {
            long reference = intent.getLongExtra( DownloadManager.EXTRA_DOWNLOAD_ID, -1 );
            if ( myDownloadReference == reference )
            {
                Query myDownloadQuery = new Query();
                myDownloadQuery.setFilterById( reference );

                Cursor myDownload = downloadManager.query( myDownloadQuery );
                if ( myDownload.moveToFirst() )
                {
                    int fileNameIdx = myDownload.getColumnIndex( DownloadManager.COLUMN_LOCAL_FILENAME );
                    int fileUriIdx = myDownload.getColumnIndex( DownloadManager.COLUMN_LOCAL_URI );

                    String fileName = myDownload.getString( fileNameIdx );
                    String fileUri = myDownload.getString( fileUriIdx );

                    // TODO Do something with the file.
                    Log.d( TAG, fileName + " : " + fileUri );
                    Intent installIntent = new Intent( Intent.ACTION_VIEW );
                    installIntent.setDataAndType( Uri.fromFile( new File( fileName ) ), "application/vnd.android.package-archive" );
                    startActivity( installIntent );
                }
                myDownload.close();

            }
        }
    };

    registerReceiver( receiver, filter );
}
 
开发者ID:amar19860330,项目名称:amar-android-demo,代码行数:44,代码来源:Internet1Activity.java

示例10: onReceive

import android.app.DownloadManager.Query; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
	String action = intent.getAction();

	if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
		long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
		if (id == Preferences.getDownloadId(context)) {
			Query query = new Query();
			query.setFilterById(id);
			downloadManager = (DownloadManager) context
					.getSystemService(Context.DOWNLOAD_SERVICE);
			Cursor cursor = downloadManager.query(query);

			int columnCount = cursor.getColumnCount();
			String path = null;
			while (cursor.moveToNext()) {
				for (int j = 0; j < columnCount; j++) {
					String columnName = cursor.getColumnName(j);
					String string = cursor.getString(j);
					if ("local_uri".equals(columnName)) {
						path = string;
					}
				}
			}
			cursor.close();

			if (path != null) {
				Preferences.setDownloadPath(context, path);
				Preferences.setDownloadStatus(context, -1);
				Intent installApkIntent = new Intent();
				installApkIntent.setAction(Intent.ACTION_VIEW);
				installApkIntent.setDataAndType(Uri.parse(path),
						"application/vnd.android.package-archive");
				installApkIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
						| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
				context.startActivity(installApkIntent);
			}
		}
	} else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) {
		long[] ids = intent
				.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
		if (ids.length > 0 && ids[0] == Preferences.getDownloadId(context)) {
			Intent downloadIntent = new Intent();
			downloadIntent.setAction(DownloadManager.ACTION_VIEW_DOWNLOADS);
			downloadIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
					| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
			context.startActivity(downloadIntent);
		}
	}
}
 
开发者ID:way1989,项目名称:WayHoo,代码行数:51,代码来源:DownloadCompleteReveiver.java

示例11: onReceive

import android.app.DownloadManager.Query; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {

	if (!intent.getAction().equals(
			DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
		return;
	}
	Log.d(TAG, "processing");

	Query query = new Query();
	query.setFilterById(enqueuedID);
	DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
	Cursor cursor = manager.query(query);

	if (!cursor.moveToFirst()) {
		cursor.close();
		return;
	}

	int columnIndex = cursor
			.getColumnIndex(DownloadManager.COLUMN_STATUS);

	if (cursor.getInt(columnIndex) != DownloadManager.STATUS_SUCCESSFUL) {
		cursor.close();
		return;
	}

	String uriString = cursor.getString(cursor
			.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
	cursor.close();

	extractFile(Uri.parse(uriString),
			DictionarySearcher.DICTIONARY_NAME);

	new File(Uri.parse(uriString).getPath()).delete();

	intent = new Intent(context,
			FloatingJapaneseDictionaryLauncherActivity.class);
	intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
			| Intent.FLAG_ACTIVITY_NEW_TASK);
	startActivity(intent);

	RUNNING = false;
	enqueuedID = -1;
	context.unregisterReceiver(receiver);

	Log.d(TAG, "stopping");
	stopSelf();

}
 
开发者ID:ispedals,项目名称:FloatingJapaneseDictionary,代码行数:51,代码来源:DictionaryManagerService.java

示例12: onReceive

import android.app.DownloadManager.Query; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
	Utils.logger("d", "ffmpegReceiver: onReceive CALLED", DEBUG_TAG);
  		long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
  		
  		//if (enqueue != -1 && id != -2 && id == enqueue) {
   		Query query = new Query();
		query.setFilterById(id);
		Cursor c = dm.query(query);
		if (c.moveToFirst()) {
		
			int statusIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
			int reasonIndex = c.getColumnIndex(DownloadManager.COLUMN_REASON);
			int status = c.getInt(statusIndex);
			int reason = c.getInt(reasonIndex);

			switch (status) {
			
			case DownloadManager.STATUS_SUCCESSFUL:
   		
				File src = new File(DIR, ffmpegBinName);
				File dst = new File(nContext.getDir("bin", 0), ffmpegBinName);
				
				String md5 = null;
				if (cpuVers == 7) md5 = "33fcf4d5a3b2e5193bd42c2c1fc2abc7";
				if (cpuVers == 5) md5 = "0606931cfbaca351a47e59ab198bc81e";
				
				if (Utils.checkMD5(md5, src)) {
					copyFfmpegToAppDataDir(context, src, dst);
				} else {
					SettingsActivity.SettingsFragment.touchAudioExtrPref(true, false);
					deleteBadDownload(id);
				}
				break;
				
			case DownloadManager.STATUS_FAILED:
				Log.e(DEBUG_TAG, ffmpegBinName + ", _ID " + id + " FAILED (status " + status + ")");
				Log.e(DEBUG_TAG, " Reason: " + reason);
				Toast.makeText(nContext,  ffmpegBinName + ": " + getString(R.string.download_failed), Toast.LENGTH_LONG).show();
				
				SettingsActivity.SettingsFragment.touchAudioExtrPref(true, false);
				deleteBadDownload(id);
				break;
				
			default:
				Utils.logger("w", ffmpegBinName + ", _ID " + id + " completed with status " + status, DEBUG_TAG);
			}
		}
  		//}
  		ffmpegBinObserver.stopWatching();
  		stopSelf();
}
 
开发者ID:thatapps,项目名称:goloader,代码行数:53,代码来源:FfmpegDownloadService.java


注:本文中的android.app.DownloadManager.Query.setFilterById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。