Reputation: 1448
I am developing one video streaming app but I'm stuck on downloading video in Android app, I want to download the video in background exact like vimeo app, in vimeo app if you want to download the video, it will starting the video downloading in another screen(Download Screen) in background, if you go in download screen it already started the video downloading, one more thing is that if you traverse through out the app, it still downloading the video in background in the download screen and when you come to the download screen it will show you the updated downloading progress.
1) To download the video in vimeo
Please give me suggestion on the downloading manager
Upvotes: 6
Views: 17282
Reputation: 6857
1) Download Manager
The Android Download Manager was introduced in Android 2.3 as a service to optimize the handling of long-running downloads.
The Download Manger handles the HTTP connection and monitors connectivity changes. Its a good practice to use Download.
Manager in most situations, particularly where a download is likely to continue in the background between user sessions.
Instances of this class should be obtained through getSystemService(String) by passing DOWNLOAD_SERVICE.
Apps that request downloads through this API should register a broadcast receiver for ACTION_NOTIFICATION_CLICKED to appropriately handle when the user clicks on a running download in a notification or from the downloads UI.
2)Running a Service in the Foreground
A foreground service is a service that's considered to be something the user is actively aware of and thus not a candidate for the system to kill when low on memory. A foreground service must provide a notification for the status bar, which is placed under the "Ongoing" heading, which means that the notification cannot be dismissed unless the service is either stopped or removed from the foreground.
For example, Download a video from a service should be set to run in the foreground, because the user is explicitly aware of its operation. The notification in the status bar might indicate the current Download and allow the user to launch an activity to interact with Download process.
To request that your service run in the foreground, call startForeground(). This method takes two parameters: an integer that uniquely identifies the notification and the Notification for the status bar.
For example:
Notification notification = new Notification(R.drawable.icon, getText(R.string.ticker_text),
System.currentTimeMillis());
Intent notificationIntent = new Intent(this, ExampleActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(this, getText(R.string.notification_title),
getText(R.string.notification_message), pendingIntent);
startForeground(ONGOING_NOTIFICATION_ID, notification);
To remove the service from the foreground, call stopForeground(). This method takes a boolean, indicating whether to remove the status bar notification as well. This method does not stop the service. However, if you stop the service
Upvotes: 0
Reputation: 333
The underlying architecture of the download system in the Vimeo app is currently in the middle of the open-sourcing process. If you can wait a few weeks you will have access to it. If not, there are plenty of other open-sourced "download" systems out there such as:
Ultimately, none of these met the exact needs of the Vimeo app, so we decided to write our own. I'll try to update this answer when it is available.
Upvotes: 1
Reputation: 3370
this code is for save into a SD card
package com.Video.ALLTestProject;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Environment;
import android.util.Log;
public class VideoSaveSDCARD extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ProgressBack PB = new ProgressBack();
PB.execute("");
}
class ProgressBack extends AsyncTask < String, String, String > {
ProgressDialog PD;
@Override
protected void onPreExecute() {
PD = ProgressDialog.show(LoginPage.this, null, "Please Wait ...", true);
PD.setCancelable(true);
}
@Override
protected void doInBackground(String...arg0) {
DownloadFile("http://beta-vidizmo.com/hilton.mp4", "Sample.mp4");
}
protected void onPostExecute(Boolean result) {
PD.dismiss();
}
}
}
more info in this thread How can I download a video file to SD card?
Upvotes: -1