Thamilvanan
Thamilvanan

Reputation: 385

Parse error while installing downloaded .apk file

Hi after Two weeks again i started my research and struggling with this Error *Parse Error:*There is a problem parsing package.

Scope of my implementation is am trying to update my app from a server where i have the updated apk file and am downloading it through my app using service .Now am at edge of the Stage i can download the file from that server an i can able to install it by manually.But my scope is like after file is downloade from the Server it should automatically invoke the installing app popup window .while installing this am getting the above error.i have tried before asking this question whoever asked the same issue here.

This is my code:

public class Myservice extends Service {
String versionName;

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public void onCreate() {
    Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();

}

@Override
public void onDestroy() {
    Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();

}

@Override
public void onStart(Intent intent, int startid) {
    try {
        versionName = getPackageManager().getPackageInfo(getPackageName(),
                0).versionName;
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }



     DownloadFromUrl();


}

public void DownloadFromUrl() {  //this is the downloader method
      try {
              URL url = new URL("http://61.12.5.34:10140/test/UpateTest.apk");
              String  file ="YeldiUpateTest.apk";

              long startTime = System.currentTimeMillis();

              /* Open a connection to that URL. */
              URLConnection ucon = url.openConnection();

              /*
               * 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(50);
              int current = 0;
              while ((current = bis.read()) != -1) {
                      baf.append((byte) current);

              }

              /* Convert the Bytes read to a String. */
              FileOutputStream fos = openFileOutput(file, Context.MODE_PRIVATE);
              Log.v("wsd", "write");
              fos.write(baf.toByteArray());
              fos.close();
              Log.d("Download time", "download ready in"
                              + ((System.currentTimeMillis() - startTime) / 1000)
                              + " sec");

              install();
      } catch (IOException e) {
              Log.d("ImageManager", "Error: " + e);
      }
 }

and this is my install method():

void install()
{

     File path=getFileStreamPath("UpateTest.apk");

     Intent intent=new Intent(Intent.ACTION_VIEW);
     intent.setDataAndType(Uri.fromFile(path), "application/vnd.android.package-archive");
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     startActivity(intent);
}

Upvotes: 2

Views: 6643

Answers (1)

Thamilvanan
Thamilvanan

Reputation: 385

Finally i can able to install my apk which was downloaded from my server without any Parse Error.I tried with external storage it was happend without any error.to store the apk in internal storage and want to install means u need to change Your

FileOutputStream fos = openFileOutput(file, Context.MODE_PRIVATE)

to Context.MODE_WORLD_READABLE. and i added permissions like INSTALL_PACKAGES.

Upvotes: 3

Related Questions