Sometimes i see your responses and wonder if you're responding to the same
topic or something completely different...
On Monday, May 20, 2013 10:48:00 PM UTC+3, bob wrote:
>
> Actually, I was looking at your code some more, and *I would want to know
> the URL you are downloading from* to get a better idea of the
> correctness. I see that you are searching for an equals sign and using
> that to find the file name.
>
> If it turns out you are coming up with an okay file name, the problem is
> almost certainly one of permissions - you will need INTERNET permission as
> well as WRITE_EXTERNAL_STORAGE.
>
> Thanks.
>
>
> On Monday, May 20, 2013 7:25:12 AM UTC-5, rahul kaushik wrote:
>>
>> Hi,
>>
>> I am trying to download the file as this is 2 mb but it is downlaoding
>> only 7.1 kb below is my code
>> 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;
>> final int BUFFER_SIZE = 128;
>> File root = android.os.Environment.getExternalStorageDirectory();
>> try {
>> URL url = new URL(f_url[0]);
>> String fileName=url.toString();;
>> // String Filename= getFileName(url);
>>
>> String newpath = fileName.replace('\\','/');
>> int start = newpath.lastIndexOf("=");
>> if ( start == -1)
>> {
>> start = 0;
>> }
>> else
>> {
>> start = start + 1;
>> }
>> String pageName = newpath.substring(start, newpath.length());
>>
>>
>> long startTime = System.currentTimeMillis();
>> Log.d("getFileName", pageName);
>>
>>
>> URLConnection ucon = url.openConnection();
>> ucon.connect();
>> int lengthofFile = ucon.getContentLength();
>> /*
>> * Define InputStreams to read from the URLConnection.
>> */
>> InputStream is = ucon.getInputStream();
>> BufferedInputStream bis = new BufferedInputStream(is);
>>
>> /*
>> * Read bytes to the Buffer until there is nothing more to
>> read(-1).
>> */
>> ByteArrayBuffer baf = new ByteArrayBuffer(50000);
>> int current = 0;
>> while ((current = bis.read()) != -1) {
>> baf.append((byte) current);
>> }
>>
>> /* Convert the Bytes read to a String. */
>> File file = new File(fileName);
>> FileOutputStream fos = new
>> FileOutputStream(Environment.getExternalStorageDirectory().toString()+
>> "/"+pageName.trim());
>> //Log.d("root:", root.toString());
>> fos.write(baf.toByteArray());
>> fos.close();
>> Log.d("ImageManager", "download ready in"
>> + ((System.currentTimeMillis() - startTime)
>> / 1000)
>> + " sec");
>>
>>
>>
>>
>>
>> } 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);
>> // String imagePath =
>> Environment.getExternalStorageDirectory().toString() +
>> "/downloadedfile.jpg";
>> // setting downloaded into image view
>> //
>> my_image.setImageDrawable(Drawable.createFromPath(imagePath));
>> }
>>
>> }
>>
>> PLease Suggest
>> Thanks
>> RK
>>
>
--
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.