use of android.app.DownloadManager in project LshUtils by SenhLinsh.
the class LshDownloadManager method queryProgress.
public void queryProgress(final QueryCallback callback) {
if (mRequestId == 0) {
callback.onFailed("没有当前任务");
return;
}
final DownloadManager manager = (DownloadManager) LshApplicationUtils.getContext().getSystemService(Context.DOWNLOAD_SERVICE);
final DownloadManager.Query query = new DownloadManager.Query().setFilterById(mRequestId);
if (query == null) {
callback.onFailed("没有当前任务");
return;
}
if (mIsQuerying) {
callback.onFailed("正在查询中");
return;
}
mIsQuerying = true;
queryProgress(manager, query, callback);
}
use of android.app.DownloadManager in project LshUtils by SenhLinsh.
the class LshDownloadManager method getProgress.
private static float getProgress(long requestId) {
if (requestId != 0) {
DownloadManager manager = (DownloadManager) LshApplicationUtils.getContext().getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Query query = new DownloadManager.Query().setFilterById(requestId);
return getProgress(manager, query);
}
return -1;
}
use of android.app.DownloadManager in project LshUtils by SenhLinsh.
the class LshDownloadManager method cancel.
public void cancel() {
if (mRequestBuilder != null && mRequestId != 0) {
DownloadManager manager = (DownloadManager) LshApplicationUtils.getContext().getSystemService(Context.DOWNLOAD_SERVICE);
manager.remove(mRequestId);
mRequestId = 0;
}
}
use of android.app.DownloadManager in project saga-android by AnandChowdhary.
the class Updater method checkForUpdates.
public static void checkForUpdates(final Context context, boolean visibility) {
final int versionCode = getVersionCode(context);
final ProgressDialog progressDialog = new ProgressDialog(context);
String updateUrl = "https://www.dropbox.com/s/bka9o3p43oki217/saga.json?raw=1";
if (visibility) {
progressDialog.setTitle(context.getString(R.string.update));
progressDialog.setMessage(context.getString(R.string.update_checking));
progressDialog.setCancelable(true);
progressDialog.show();
}
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, updateUrl, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
int updateVersionCode = response.getInt("versionCode");
if (updateVersionCode > versionCode && versionCode != 0) {
if (progressDialog.isShowing()) {
progressDialog.cancel();
}
final String apkUrl = response.getString("apkUrl");
String changelog = response.getString("changelog");
AlertDialog dialog = new AlertDialog.Builder(context).setTitle(context.getString(R.string.new_update)).setMessage(changelog).setPositiveButton(context.getString(R.string.update_now), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
File myFile = new File(Utils.getStoragePath(context), "update.apk");
if (myFile.exists())
myFile.delete();
Uri uri = Uri.parse(apkUrl);
DownloadManager dMgr = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request dr = new DownloadManager.Request(uri);
String filename = "update.apk";
dr.setTitle(context.getString(R.string.app_name) + " " + context.getString(R.string.update));
dr.setDestinationUri(Uri.fromFile(new File(Utils.getStoragePath(context) + "/" + filename)));
// dr.setDestinationInExternalPublicDir("/Saga/", filename);
dMgr.enqueue(dr);
}
}).setNegativeButton(context.getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).setCancelable(false).create();
dialog.show();
} else {
if (progressDialog.isShowing()) {
progressDialog.cancel();
Toast.makeText(context, context.getString(R.string.no_update), Toast.LENGTH_SHORT).show();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (progressDialog.isShowing()) {
progressDialog.cancel();
Toast.makeText(context, context.getString(R.string.error_connect), Toast.LENGTH_SHORT).show();
}
}
});
request.setShouldCache(false);
VolleySingleton.getInstance(context).getRequestQueue().add(request);
}
use of android.app.DownloadManager in project AndroidChromium by JackyAndroid.
the class DownloadBroadcastReceiver method openDownload.
/**
* Called to open a given download item that is downloaded by the android DownloadManager.
* @param context Context of the receiver.
* @param intent Intent from the android DownloadManager.
*/
private void openDownload(final Context context, Intent intent) {
long[] ids = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
if (ids == null || ids.length == 0) {
DownloadManagerService.openDownloadsPage(context);
return;
}
long id = ids[0];
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = manager.getUriForDownloadedFile(id);
if (uri == null) {
// Open the downloads page
DownloadManagerService.openDownloadsPage(context);
} else {
String downloadFilename = IntentUtils.safeGetStringExtra(intent, DownloadNotificationService.EXTRA_DOWNLOAD_FILE_PATH);
boolean isSupportedMimeType = IntentUtils.safeGetBooleanExtra(intent, DownloadNotificationService.EXTRA_IS_SUPPORTED_MIME_TYPE, false);
Intent launchIntent = DownloadManagerService.getLaunchIntentFromDownloadId(context, downloadFilename, id, isSupportedMimeType);
if (!DownloadUtils.fireOpenIntentForDownload(context, launchIntent)) {
DownloadManagerService.openDownloadsPage(context);
}
}
}
Aggregations