Comments (3)
Fetch will continue to download the file in the background. If you intent service is killed, The instance of Fetch will no longer receive status updates via the Fetch Listener but the download will still be processing in the background. If you would like to share your code or an example, I would be glad to have a look.
from fetch.
Thanks for the reply. Sorry for not being clear! when I start download and then I press the home button my app goes in the background and the download continues, but when I kill the app from background ( Keeping the home button pressed and then killing the process) the download stops. I have written a simple download program that continues downloading even if I kill the app process, but that program is not very stable and useful so I decided to use Fetch.
The following the my code snippet.
public void startDownload(final String name, final String packageName, final String path, final boolean obb, final boolean data) {
try {
final Fetch fetch = Fetch.getInstance(this);
Intent i = new Intent(getApplicationContext(), DownloadListView.class);
PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, i, 0);
mBuilder = new NotificationCompat.Builder(this);
mBuilder.setContentTitle(name)
.setContentText("Downloading")
.setSmallIcon(R.drawable.image)
.setContentInfo("0%")
.setProgress(100, 0, true)
.setContentIntent(pi)
.setOngoing(true)
.setAutoCancel(true);
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notification = mBuilder.build();
//this method is used to run the app in foreground even if it is killed from background
startForeground(notificationId, notification);
url = IPClass.SERVERIP + path + "/" + packageName;
String dirPath = "/sdcard/Android/appdata/tmp/downloadtmp";
Request request = new Request(url, dirPath, packageName);
if (fetch.contains(request)) {
//getting the download id from database
fetch.resume(new DatabaseTools(getApplicationContext()).getFetchId(packageName));
}else{
downloadId = fetch.enqueue(request);
//stroing the downloadId to the database for future use
new DatabaseTools(getApplicationContext()).setDownloadID(packageName, downloadId);
}
fetch.addFetchListener(new FetchListener() {
@Override
public void onUpdate(long id, int status, int progress, long downloadedBytes, long fileSize, int error) {
if (progress < 100) {
if (downloadId == id && status == Fetch.STATUS_DOWNLOADING) {
int downloadedKB = (int) downloadedBytes / 1024;
if (downloadedKB < 1024) {
mBuilder.setProgress(100, Integer.valueOf(progress), false).setContentInfo(progress + "%" + " | " + downloadedKB + " KB");
nm.notify(notificationId, mBuilder.build());
} else {
float downloadedMB = (float) downloadedKB / 1024;
double dMB = (float) Math.round(downloadedMB * 100.0) / 100.0;
mBuilder.setProgress(100, Integer.valueOf(progress), false).setContentInfo(progress + "%" + " | " + dMB + " MB");
nm.notify(notificationId, mBuilder.build());
}
}
} else {
Long tmpid = new DatabaseTools(getApplicationContext()).getFetchId(packageName);
fetch.remove(tmpid);
//calling asynch task to unzip the downloaded file if it is .zip otherwise prompt user for installation
new DownloadFinished(name, packageName, obb, data).execute();
}
}
});
} catch (Exception ex) {
} finally {
fetch.release();
}
}
Also another small problem I am facing is when all downloads are stopped by any reason and I start a new download the new download goes to the queue, but Fetch starts downloading a previously enqueued one!
Thanks for the help!
from fetch.
@ahshoaib sorry for the late reply. When you kill an application's process, everything that runs in the process is killed(The way it suppose to work). Fetch does not run on an independent process. It runs on your applications process, so it will be killed and downloading will stop.
What you are describing seems more like an application design issue. What I recommend doing is scheduling an alarm, Job Service or broadcast receiver that can start the Fetch Service in the background and continue to download requests. To do this you can simply call Fetch.startService(context);
(Note this is called on the Fetch class) from the component to start downloading in the background. I would also recommend putting Fetch.startService(context);
in your Application class onCreate
method. That way, whenever your application process starts, the FetchService starts.
For your second question, Fetch is a queue based downloading service. The first request in the queue will get processed first, then the next and so on. Fetch does not currently support multi downloading. Fetch does support priority downloading. If there is a download that you want to execute immediately without waiting in the queue. you can call fetch.setPriority(downloadId, Fetch.PRIORITY_HIGH);
. You can also set the priority when creating a request:
Request request = new Request(url,filePath);
request.setPriority(Fetch.PRIORITY_HIGH);
fetch.enqueue(request);
Note that if you enqueue several request with Fetch.PRIORITY_HIGH
they all will be downloaded in the order they were enqueued but will be downloaded before Fetch.PRIORITY_NORMAL
requests.
If you would like more control of the FetchService, you can interact with it via intents and broadcast receivers. I have not documented the FetchService class yet, but it is simple enough to follow along. Hope this helps.
from fetch.
Related Issues (20)
- Repeat download a file and cause unknown error
- Timeout for Fetch Request
- some of files disappeared after download HOT 1
- Chain validation failed HOT 1
- Facing issue while generate
- Caused by: org.gradle.api.resources.ResourceException: Could not get resource 'https://jitpack.io/com/tonyodev/fetch2/fetch2/3.0.12/fetch2-3.0.12.pom'. HOT 3
- The free download manager application download stuck in queued in mobile
- Download groups separately
- Gradle implementation can not find HOT 1
- Parallel Download type causes to increase the network usage about five times more than what it is
- android.database.sqlite.SQLiteException
- removeListener has bugs
- when use OkHttpDownloader, App will crash with OOM HOT 1
- java.lang.SecurityException: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts HOT 6
- Today i face error :Failed to resolve: HOT 8
- Download is not working or resume after killing application
- This fetch instance has been closed. Create a new instance using the builder HOT 3
- Please adapt for Android 14 HOT 17
- Feth listener onComplete() called twice HOT 1
- Fetch does not throw exception when internet connection get lost
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fetch.