Download image from 'download url' Android - android

There are tons of download image from url codes. But is it possible to download image from url that already action download? I mean ;
Tons of codes about download the this image from that link
But I want to download image to android device from this link
Is it possible ?
Thanks

Nothing hard in this.
public class DownloadImage extends Activity {
String image_URL=http://www.hdwallpapers.in/download/minions_2015-1280x720.jpg; // give image name to save in sd card
String extStorageDirectory;
String sdCard;
Bitmap bitmap;
File file;
String savedFilePath;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonSave = (Button)findViewById(R.id.save);
ImageView bmImage = (ImageView)findViewById(R.id.image);
buttonSave.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
myAsyncTask myWebFetch = new myAsyncTask();
myWebFetch.execute();
}
});
}
class myAsyncTask extends AsyncTask<Void, Void, Void> {
TextView tv;
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
dialog.dismiss();
}
#Override
protected void onPreExecute() {
super.onPreExecute();
public ProgressDialog dialog;
dialog = new ProgressDialog(DownloadImage.this);
dialog.setMessage("Loading...");
dialog.setCancelable(false);
dialog.setIndeterminate(true);
dialog.show();
}
protected Void doInBackground(Void... arg0) {
try {
//set the download URL, a url that points to a file on the internet
//this is the file to be downloaded
URL url = new URL(image_URL);
//create the new connection
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
//set up some things on the connection
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
//and connect!
urlConnection.connect();
//set the path where we want to save the file
//in this case, going to save it on the root directory of the
//sd card.
File SDCardRoot = Environment.getExternalStorageDirectory();
//create a new file, specifying the path, and the filename
//which we want to save the file as.
File file = new File(SDCardRoot,"somefile.jpg");
//this will be used to write the downloaded data into the file we created
FileOutputStream fileOutput = new FileOutputStream(file);
//this will be used in reading the data from the internet
InputStream inputStream = urlConnection.getInputStream();
//this is the total size of the file
int totalSize = urlConnection.getContentLength();
//variable to store total downloaded bytes
int downloadedSize = 0;
//create a buffer...
byte[] buffer = new byte[1024];
int bufferLength = 0; //used to store a temporary size of the buffer
//now, read through the input buffer and write the contents to the file
while ( (bufferLength = inputStream.read(buffer)) > 0 ) {
//add the data in the buffer to the file in the file output stream (the file on the sd card
fileOutput.write(buffer, 0, bufferLength);
//add up the size so we know how much is downloaded
downloadedSize += bufferLength;
//this is where you would do something to report the prgress, like this maybe
//updateProgress(downloadedSize, totalSize);
}
//close the output stream when done
fileOutput.close();
//catch some possible errors...
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
}
Now you downloaded image directly in sd card. Don't forget to give permission in manifest for external storage.

Try to check out this tutorial, was very helpful to me. He uses a custom class called ImageLoader with a public method DisplayImage(String url, int loader, ImageView imageView), you can call it this way:
int loader = R.drawable.loader;
// Imageview to show
ImageView image = (ImageView) findViewById(R.id.image);
// Image url
String image_url = "http://www.example.com/images/sample.jpg";
// ImageLoader class instance
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
imgLoader.DisplayImage(image_url, loader, image);

Related

How to download multiple images from urls in a single process?

I create app for download multi images, from url, the problem is when download all images (there's 3000 images) its multi process, not single process. Single process I mean download and then save, download and then save and so on.
It's possible to download multi image with single process ?
this is my code :
private CoordinatorLayout mCLayout;
private ProgressDialog mProgressDialog;
private LinearLayout mLLayout;
private AsyncTask mMyTask;
private final URL[] URLS = {
stringToURL("https://d1rkccsb0jf1bk.cloudfront.net/products/3d/100009884/images/I_20.jpg"),
stringToURL("https://d3inagkmqs1m6q.cloudfront.net/2280/media-photos/azk0w23602-black-new-calvin-klein-watches-k0w23602.jpg"),
stringToURL("https://www.designerswatch.com.au/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/k/2/k2y211c3-1.jpg"),
stringToURL("http://demandware.edgesuite.net/sits_pod35/dw/image/v2/ABAD_PRD/on/demandware.static/-/Sites-calvinklein-hk-master/default/dw521470a6/images/hi-res/K7Y214CZ-000/K7Y214CZ-000-ITEM-1.jpg?sw=500"),
stringToURL("https://ethos-cdn1.ethoswatches.com/pub/media/catalog/product/cache/749a04adc68de020ef4323397bb5eac7/c/a/calvin-klein-party-k8u2m116.jpg")
// and so on
};
int count;
// List of url image
List<URL> imageName = new ArrayList<>();
File file;
ContextWrapper wrapper;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get the application context
getApplicationContext();
Activity mActivity = MainActivity.this;
// Get the widget reference from XML layout
mCLayout = findViewById(R.id.coordinator_layout);
Button mButtonDo = findViewById(R.id.btn_do);
mLLayout = findViewById(R.id.ll);
//-------------------set image--------------------------
ImageView setImage = findViewById(R.id.setImage);
// Initialize ContextWrapper
wrapper = new ContextWrapper(getApplicationContext());
file = wrapper.getDir("Images",MODE_PRIVATE);
file = new File(file, "I_20.jpg");
if(file.exists()) {
Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
setImage.setImageBitmap(myBitmap);
}
//-------------------set image--------------------------
// Initialize the progress dialog
mProgressDialog = new ProgressDialog(mActivity);
mProgressDialog.setIndeterminate(false);
// Progress dialog horizontal style
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// Progress dialog title
mProgressDialog.setTitle("AsyncTask");
// Progress dialog message
mProgressDialog.setMessage("Please wait, we are downloading your image files...");
mProgressDialog.setCancelable(true);
// Set a progress dialog dismiss listener
mProgressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
#Override
public void onDismiss(DialogInterface dialogInterface) {
// Cancel the AsyncTask
mMyTask.cancel(false);
}
});
// Initialize a new click listener for positive button widget
mButtonDo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// Execute the async task
mMyTask = new DownloadTask().execute(URLS);
}
});
}
/*
* First parameter URL for doInBackground
* Second parameter Integer for onProgressUpdate
* Third parameter List<Bitmap> for onPostExecute
*/
#SuppressLint("StaticFieldLeak")
private class DownloadTask extends AsyncTask<URL,Integer,List<Bitmap>>{
// Before the tasks execution
protected void onPreExecute(){
// Display the progress dialog on async task start
mProgressDialog.show();
mProgressDialog.setProgress(0);
}
// Do the task in background/non UI thread
protected List<Bitmap> doInBackground(URL...urls){
Log.d("doInBackground", "doInBackground: ");
count = urls.length;
//URL url = urls[0];
HttpURLConnection connection = null;
List<Bitmap> bitmaps = new ArrayList<>();
// Loop through the urls
for(int i=0;i<count;i++){
URL currentURL = urls[i];
// So download the image from this url
try{
// Initialize a new http url connection
connection = (HttpURLConnection) currentURL.openConnection();
// Connect the http url connection
connection.connect();
// Get the input stream from http url connection
InputStream inputStream = connection.getInputStream();
// Initialize a new BufferedInputStream from InputStream
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
// Convert BufferedInputStream to Bitmap object
Bitmap bmp = BitmapFactory.decodeStream(bufferedInputStream);
// Add the bitmap to list
bitmaps.add(bmp);
// add the url to list URL
imageName.add(currentURL);
// Publish the async task progress
// Added 1, because index start from 0
publishProgress((int) (((i+1) / (float) count) * 100));
if(isCancelled()){
break;
}
}catch(IOException e){
e.printStackTrace();
}finally{
// Disconnect the http url connection
assert connection != null;
connection.disconnect();
}
}
// Return bitmap list
return bitmaps;
}
// On progress update
protected void onProgressUpdate(Integer... progress){
// Update the progress bar
mProgressDialog.setProgress(progress[0]);
}
// On AsyncTask cancelled
protected void onCancelled(){
Snackbar.make(mCLayout,"Task Cancelled.",Snackbar.LENGTH_LONG).show();
}
// When all async task done
protected void onPostExecute(List<Bitmap> result){
// Hide the progress dialog
mProgressDialog.dismiss();
// Remove all views from linear layout
mLLayout.removeAllViews();
Log.d("result", String.valueOf(result));
// Loop through the bitmap list
for(int i=0;i<result.size();i++){
Bitmap bitmap = result.get(i);
// Save the bitmap to internal storage
Uri imageInternalUri = saveImageToInternalStorage(bitmap, i);
// Display the bitmap from memory
addNewImageViewToLayout(bitmap);
// Display bitmap from internal storage
// addNewImageViewToLayout(imageInternalUri);
}
}
}
// Custom method to convert string to url
protected URL stringToURL(String urlString){
try{
return new URL(urlString);
}catch(MalformedURLException e){
e.printStackTrace();
}
return null;
}
// Custom method to save a bitmap into internal storage
protected Uri saveImageToInternalStorage(Bitmap bitmap, int index){
Log.d("count", String.valueOf(count));
// Initializing a new file
// The bellow line return a directory in internal storage
file = wrapper.getDir("Images",MODE_PRIVATE);
// Create a file to save the image
// First get name of image from url, and then saved with that name
file = new File(file, getFileNameFromUrl(imageName.get(index)));
Log.d("TAG", String.valueOf(file));
try{
// Initialize a new OutputStream
OutputStream stream;
// If the output file exists, it can be replaced or appended to it
stream = new FileOutputStream(file);
// Compress the bitmap
bitmap.compress(Bitmap.CompressFormat.JPEG,100,stream);
// Flushes the stream
stream.flush();
// Closes the stream
stream.close();
}catch (IOException e) // Catch the exception
{
e.printStackTrace();
}
// Parse the gallery image url to uri
// Return the saved image Uri
return Uri.parse(file.getAbsolutePath());
}
/**
* This function will take an URL as input and return the file name.
* Examples :
* http://example.com/a/b/c/test.txt -> test.txt
* http://example.com/ -> an empty string
* http://example.com/test.txt?param=value -> test.txt
* http://example.com/test.txt#anchor -> test.txt
*
* #param url The input URL
* #return The URL file name
*/
public static String getFileNameFromUrl(URL url) {
// String file
String urlString = url.getFile();
// Return image name
return urlString.substring(urlString.lastIndexOf('/') + 1).split("\\?")[0].split("#")[0];
}
// Custom method to add a new image view using bitmap
protected void addNewImageViewToLayout(Bitmap bitmap){
// Initialize a new ImageView widget
ImageView iv = new ImageView(getApplicationContext());
// Set an image for ImageView
iv.setImageBitmap(bitmap);
// Create layout parameters for ImageView
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, 500);
// Add layout parameters to ImageView
iv.setLayoutParams(lp);
// Finally, add the ImageView to layout
mLLayout.addView(iv);
}
// Custom method to add a new image view using uri
protected void addNewImageViewToLayout(Uri uri){
// Initialize a new ImageView widget
ImageView iv = new ImageView(getApplicationContext());
// Set an image for ImageView
iv.setImageURI(uri);
// Create layout parameters for ImageView
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, 300);
// Add layout parameters to ImageView
iv.setLayoutParams(lp);
// Finally, add the ImageView to layout
mLLayout.addView(iv);
}
my goal is to make it like this, because I got error, Clamp target GC heap I think the problem is BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); because many images.
thanks a lot
Use DownloadManager to download multiple images
public static void downloadFile(String uRl, Context context) {
File myDir = new File(Environment.getExternalStorageDirectory(), "MyApp/");
if (!myDir.exists()) {
myDir.mkdirs();
}
DownloadManager mgr = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Uri downloadUri = Uri.parse(uRl);
DownloadManager.Request request = new DownloadManager.Request(
downloadUri);
request.setAllowedNetworkTypes(
DownloadManager.Request.NETWORK_WIFI
| DownloadManager.Request.NETWORK_MOBILE).setAllowedOverMetered(true)
.setAllowedOverRoaming(true).setTitle("Myapp - " + "Downloading " + uRl).
setVisibleInDownloadsUi(true)
.setDestinationInExternalPublicDir("MyApp" + "/", uRl);
mgr.enqueue(request);
}
Usage:-
// Initialize a new click listener for positive button widget
mButtonDo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// Execute the async task
// mMyTask = new DownloadTask().execute(URLS);
for (int i = 0; i < URLS .size(); i++) {
downloadFile(urls[i],Activityname.this);
}
}
});
To change path , edit this
File myDir = new File(Environment.getExternalStorageDirectory(), "MyApp/");

How to save and display images with Picasso

I'm not too familiar with Picasso, but my app uses it to load images from their URL.
But I want to make a button which when it's clicked, it would mark the image as favorite, displaying it even when it's offline.
I'm saving the other stuff (strings, doubles) with a Content Provider.
So, I think the best way to accomplish this is saving the image to display even offline.
But how to I save them?
There is another good choice for downloading Image with url. Try for this code .
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new DownloadFile().execute("https://i.stack.imgur.com/w4kCo.jpg");
}
class DownloadFile extends AsyncTask<String,Integer,Long> {
ProgressDialog mProgressDialog = new ProgressDialog(MainActivity.this);// Change Mainactivity.this with your activity name.
String strFolderName;
#Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog.setMessage("Downloading Image ...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.setMax(100);
mProgressDialog.setCancelable(false);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.show();
}
#Override
protected Long doInBackground(String... aurl) {
int count;
try {
URL url = new URL((String) aurl[0]);
URLConnection conexion = url.openConnection();
conexion.connect();
String targetFileName="downloadedimage.jpg";//Change name and subname
int lenghtOfFile = conexion.getContentLength();
String PATH = Environment.getExternalStorageDirectory()+"/myImage/";
File folder = new File(PATH);
if(!folder.exists()){
folder.mkdir();//If there is no folder it will be created.
}
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(PATH+targetFileName);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress ((int)(total*100/lenghtOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {}
return null;
}
protected void onProgressUpdate(Integer... progress) {
mProgressDialog.setProgress(progress[0]);
if(mProgressDialog.getProgress()==mProgressDialog.getMax()){
mProgressDialog.dismiss();
Toast.makeText(getApplicationContext(), "Download Completed !", Toast.LENGTH_LONG).show();
}
}
protected void onPostExecute(String result) {
}
}
And set downloaded image bitmap to Imageview .
This is code. By this strategy Picasso will look for images in cache and if it failed only then image will be downloaded over network.
Picasso.with(context)
.load(Uri.parse(getItem(position).getStoryBigThumbUrl()))
.networkPolicy(NetworkPolicy.OFFLINE)
.into(holder.storyBigThumb, new Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError() {
// Try again online if cache failed
Picasso.with(context)
.load(Uri.parse(getItem(position)
.getStoryBigThumbUrl()))
.placeholder(R.drawable.user_placeholder)
.error(R.drawable.user_placeholder_error)
.into(holder.storyBigThumb);
}
});
Picasso have its own cache you wont be need to handle anything on your own.

bitmap image not displayed in imageview

I am created a app in which i am allowing user to select image from gallery or take a picture from camera and upload that image to web server.This code works fine.Now in other screen i am downloading the image from web server and storing that in sd card.The problem that if image is selected from the gallery the image is being displayed in the image view,but if the image is captured from the camera that image is not being displayed in the image view even though the file is present in the sd card
Code to display image and download from server
private static class DownloadImage extends AsyncTask<String, Void, String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected String doInBackground(String... params) {
String filePath = downloadFile("my web service");
return filePath;
}
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (result.equalsIgnoreCase("")) {
ivProfilePic.setImageDrawable(context.getResources().getDrawable(R.drawable.user_default));
progressBar.setVisibility(View.GONE);
} else {
profilePicPath = result;
Bitmap bitmapProfilePic = BitmapFactory.decodeFile(profilePicPath);
ivProfilePic.setImageBitmap(bitmapProfilePic);
progressBar.setVisibility(View.GONE);
}
}
}
public static String downloadFile(String url, String dest_file_path) {
try {
File dest_file = new File(dest_file_path);
URL u = new URL(url);
URLConnection conn = u.openConnection();
int contentLength = conn.getContentLength();
DataInputStream stream = new DataInputStream(u.openStream());
byte[] buffer = new byte[contentLength];
stream.readFully(buffer);
stream.close();
DataOutputStream fos = new DataOutputStream(new FileOutputStream(dest_file));
fos.write(buffer);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
return "";
} catch (IOException e) {
return "";
}
return dest_file_path;
}
You should scale image before display it to ImageView.
Once i was facing same problem and scaling of bitmap solve my problem.
Below is code to do so-
Bitmap b = BitmapFactory.decodeByteArray(bitmapProfilePic , 0, bitmapProfilePic .length)
ivProfilePic.setImageBitmap(Bitmap.createScaledBitmap(b, 120, 120, false));
hope this will solve your problem
All the best.
Got this issue on a KITKAT(API 19) device, but not on device running on LOLLIPOP_MR1(API 22). I guess with API 22 or above no need to do the createScaledBitmap, but for device running on API 19 or below, it will need something like this:
Bitmap myPictureBitmap = BitmapFactory.decodeFile(imagePath);
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
myPictureBitmap = Bitmap.createScaledBitmap(myPictureBitmap, ivMyPicture.getWidth(),ivMyPicture.getHeight(),true);
}
ivMyPicture.setImageBitmap(myPictureBitmap);

Android: How to create a direct download link in android

Can anyone give me an idea on how to create a textview which has a link and when the user click it, the file from that link will be automatically downloaded by the device
EDIT:
here's the code were working on:
String link = "http://www.exampleurl.com/"+pref.getString("fsfile" + count, null);
link = link.replaceAll(" ", "%20");
fsfile.setText("Attached File");
fsfile.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// starting new Async Task
new DownloadFileFromURL().execute(link);
}
});
but it seems the String link is not identified inside the .setOnClickListener
Thats quite easy
http://developer.android.com/reference/android/app/DownloadManager.html
Example: http://androidtrainningcenter.blogspot.co.at/2013/05/android-download-manager-example.html
And start this method after clicking the textview (Catch with Handler or listener)
/**
* Start Download
*/
public void startDownload() {
DownloadManager mManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
Request mRqRequest = new Request(
Uri.parse("http://androidtrainningcenter.blogspot.in/2012/11/android-webview-loading-custom-html-and.html"));
mRqRequest.setDescription("This is Test File");
// mRqRequest.setDestinationUri(Uri.parse("give your local path"));
long idDownLoad=mManager.enqueue(mRqRequest);
}
But be sure you are min. on API 9
Please use the below code onclick of TextView:
<Your TextView>.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// starting new Async Task
new DownloadFileFromURL().execute(<Your URL String>);
}
});
DownloadFromURL.java
public class DownloadFileFromURL extends AsyncTask<String, String, String> {
/**
* Before starting background thread
* Show Progress Bar Dialog
* */
#Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(progress_bar_type);
}
/**
* Downloading file in background thread
* */
#Override
protected String doInBackground(String... f_url) {
int count;
try {
URL url = new URL(f_url[0]);
URLConnection conection = url.openConnection();
conection.connect();
// getting file length
int lenghtOfFile = conection.getContentLength();
// input stream to read file - with 8k buffer
InputStream input = new BufferedInputStream(url.openStream(), 8192);
// Output stream to write file
OutputStream output = new FileOutputStream("/sdcard/downloadedfile.jpg");
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
// After this onProgressUpdate will be called
publishProgress(""+(int)((total*100)/lenghtOfFile));
// writing data to file
output.write(data, 0, count);
}
// flushing output
output.flush();
// closing streams
output.close();
input.close();
} catch (Exception e) {
Log.e("Error: ", e.getMessage());
}
return null;
}
/**
* Updating progress bar
* */
protected void onProgressUpdate(String... progress) {
// setting progress percentage
pDialog.setProgress(Integer.parseInt(progress[0]));
}
/**
* After completing background task
* Dismiss the progress dialog
* **/
#Override
protected void onPostExecute(String file_url) {
// dismiss the dialog after the file was downloaded
dismissDialog(progress_bar_type);
// Displaying downloaded image into image view
// Reading image path from sdcard
String imagePath = Environment.getExternalStorageDirectory().toString() + "/downloadedfile.jpg";
// setting downloaded into image view
my_image.setImageDrawable(Drawable.createFromPath(imagePath));
}
}

android 2.1 AsyncTask file download not working for multiple thread work fine when call single instance

i am using android 2.1 ,api level 7 and try to implement asynchronous file download from LAN server
for this i am trying to implement AsyncTask .When i am trying to call a single thread it works find but when call multiple its just stop both the thread
/* AsyncTask class*/
class DownloadFileAsync extends AsyncTask<String, String, String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected String doInBackground(String... aurl) {
int count;
try {
URL url = new URL(aurl[0]);
Log.i("count","in");
URLConnection conexion = url.openConnection();
Log.i("count","in1");
conexion.connect();
Log.i("count","in2");
File root = android.os.Environment.getExternalStorageDirectory();
Log.i("count","in3");
int lenghtOfFile = conexion.getContentLength();
Log.i("count","in4");
BufferedInputStream input = new BufferedInputStream(url.openStream());
Log.i("count","in5");
OutputStream output = new FileOutputStream(root.getAbsolutePath() + "/video" +aurl[1] +".mp4");
byte data[] = new byte[1024];
long total = 0;
Log.i("count","in6");
while ((count = input.read(data)) != -1) {
//Log.i("count","in7");
total += count;
Log.i("count",aurl[1]);
publishProgress(""+(int)((total*100)/lenghtOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {}
return null;
}
protected void onProgressUpdate(String... progress) {
Log.i("progress",progress[0]);
}
#Override
protected void onPostExecute(String unused) {
Log.i("process","end");
}
}
/*main method call*/
private void startDownload() {
Log.v("count","out");
String url = lanurl+"titanic/video"+1+"_en.m4v";
new DownloadFileAsync().execute(url,"1");
url = lanurl+"titanic/video"+2+"_en.m4v";
new DownloadFileAsync().execute(url,"2");
}
output :
download both file in sd card
but no file downloading properly
I didn't understand the complete Question. But seems like your problem is with AsyncTask.
Single Object created for an AsyncTask can be used only once. If you want to use it again, you need to create an another object for the same AsyncTask.

Categories

Resources