[android-developers] Downloaded .apk file always gives package parsing error on installations

2012-01-20 Thread rahul verma
hi everyone,
i am caught in a big problem...

I have made a downloading app. it works fine ,but one big problem is
there.

When i am downloading a .apk file using my code,on installing the
downloaded file i am always getting a package parsing error

My code:


 try {
URL url = new URL(link);
HttpURLConnection connection;
try {
connection = (HttpURLConnection) 
url.openConnection();
 File file=new 
File(SDCardDir+File.separator
+DownloadEverythingPro+File.separator+fileName);
if(file.exists()){
 downloaded = (int) file.length();
 status=Handlerr.RESUMED;
 
connection.setRequestProperty(Range, bytes=+
(file.length())+-);

}
else{
downloaded=0;
connection.setRequestProperty(Range, 
bytes= + 0 +
-);
status=Handlerr.FRESH_DOWNLOAD;

}
connection.setDoInput(true);
connection.setDoOutput(true);
j=connection.getContentLength();
int lastSlash = 
url.toString().lastIndexOf('/');
fileName = file.bin;
if(lastSlash =0)
{
fileName = 
url.toString().substring(lastSlash + 1);
}
if(fileName.equals())
{
fileName = file.bin;
}



k=j+downloaded;
BufferedInputStream in = new
BufferedInputStream(connection.getInputStream());
FileOutputStream fos=(downloaded==0)? 
new
FileOutputStream(SDCardDir+File.separator
+DownloadEverythingPro+File.separator+fileName): new
FileOutputStream(SDCardDir+File.separator
+DownloadEverythingPro+File.separator+fileName,true);
BufferedOutputStream bout = new 
BufferedOutputStream(fos,
1024);
   byte[] data = new byte[1024];
   int x = 0;
   while ((x = in.read(data, 0, 1024)) = 
0) {
   bout.write(data, 0, x);

downloaded += x;

informMiddle(status+!+downloaded+/+k
+!+this.fileName+!+this.link2);
   }
   in.close();
   fos.close();
   bout.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}



} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;

}

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Downloaded .apk file always gives package parsing error on installations

2012-01-20 Thread Kristopher Micinski
What is the package parsing error you get?

Do you have a logcat dump of what you get on install?

kris

On Fri, Jan 20, 2012 at 7:45 AM, rahul verma rahulsgonnar...@gmail.com wrote:
 hi everyone,
 i am caught in a big problem...

 I have made a downloading app. it works fine ,but one big problem is
 there.

 When i am downloading a .apk file using my code,on installing the
 downloaded file i am always getting a package parsing error

 My code:


  try {
                                URL url = new URL(link);
                                HttpURLConnection connection;
                                try {
                                        connection = (HttpURLConnection) 
 url.openConnection();
                                         File file=new 
 File(SDCardDir+File.separator
 +DownloadEverythingPro+File.separator+fileName);
                                        if(file.exists()){
                                             downloaded = (int) file.length();
                                             status=Handlerr.RESUMED;
                                             
 connection.setRequestProperty(Range, bytes=+
 (file.length())+-);

                                        }
                                    else{
                                        downloaded=0;
                                        connection.setRequestProperty(Range, 
 bytes= + 0 +
 -);
                                        status=Handlerr.FRESH_DOWNLOAD;

                                    }
                                        connection.setDoInput(true);
                                        connection.setDoOutput(true);
                                        j=connection.getContentLength();
                                        int lastSlash = 
 url.toString().lastIndexOf('/');
                                        fileName = file.bin;
                                        if(lastSlash =0)
                                        {
                                            fileName = 
 url.toString().substring(lastSlash + 1);
                                        }
                                        if(fileName.equals())
                                        {
                                            fileName = file.bin;
                                        }



                                        k=j+downloaded;
                                        BufferedInputStream in = new
 BufferedInputStream(connection.getInputStream());
                                        FileOutputStream fos=(downloaded==0)? 
 new
 FileOutputStream(SDCardDir+File.separator
 +DownloadEverythingPro+File.separator+fileName): new
 FileOutputStream(SDCardDir+File.separator
 +DownloadEverythingPro+File.separator+fileName,true);
                                        BufferedOutputStream bout = new 
 BufferedOutputStream(fos,
 1024);
                                       byte[] data = new byte[1024];
                                       int x = 0;
                                       while ((x = in.read(data, 0, 1024)) = 
 0) {
                                       bout.write(data, 0, x);

                                            downloaded += x;
                                            
 informMiddle(status+!+downloaded+/+k
 +!+this.fileName+!+this.link2);
                                       }
                                       in.close();
                                       fos.close();
                                       bout.close();
                                } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                        return;
                                }



                        } catch (MalformedURLException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                                return;

                        }

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 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 post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en