本文整理汇总了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;
}
示例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);
}
}
}
}
示例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;
}
示例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;
}
示例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();
}
}
}
}
}
示例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());
}
示例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));
}
示例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);
}
示例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 );
}
示例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);
}
}
}
示例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();
}
示例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();
}