Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5974301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:55:26+00:00 2026-05-22T20:55:26+00:00

I have an app hosted on SourceForge (https://sourceforge.net/projects/pokedroid/). I decided to add a button

  • 0

I have an app hosted on SourceForge (https://sourceforge.net/projects/pokedroid/). I decided to add a button to download the newest version of the app straight from the CVS server. The .apk downloads fine, but when I try to install it, the package installer gives a “cannot parse package” error. The code I’m using:

    private class DownloadAndInstall extends AsyncTask<String, Integer, Boolean>
{
    protected Boolean doInBackground(String... derp)
    {
        String ur=derp[0];
        String fileName=derp[1];
        ByteArrayBuffer baf = new ByteArrayBuffer(50);

        try
        {
            URL url = new URL(ur);
            URLConnection ucon = null;
            ucon = url.openConnection();

            InputStream is = ucon.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is);

            int current = 0;
            int updateCount=0;
            while ((current = bis.read()) != -1)
            {
                if(updateCount==256)
                {
                    publishProgress(baf.length());
                    updateCount=0;
                }
                baf.append((byte) current);
                updateCount++;
            }

            FileOutputStream fos = PokeDroid.openFileOutput(fileName, Context.MODE_WORLD_READABLE);
            fos.write(baf.toByteArray());
            fos.close();

        } catch (Exception e) {
            Log.e("pokedroid", e.toString());
        }

        MessageDigest digest = null;
        try {
            digest = java.security.MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            Log.e("pokedroid", e.toString());
        }
        digest.update(baf.toByteArray());
        byte[] h = digest.digest();

        if(baf.length()==0)
            return null;
        String[] fileList=fileList();
        boolean exists=false;
        for(String i:fileList)
            if(i.equals("updatehash.md5"))
                exists=true;

        String newHash=new String(h);
        Log.e("pokedroid", "new="+newHash);

        if(exists)
        {
            try
            {
                String oldHash=loadObject("updatehash.md5");
                Log.e("pokedroid", "old="+oldHash);
                if(oldHash.equals(newHash))
                    return false;
                else
                    saveObject(newHash, "updatehash.md5");
            }
            catch (Exception e)
            {
                Log.e("pokedroid",e.toString());
            }
        }
        else
        {
            try {
                saveObject(newHash, "updatehash.md5");
            } catch (IOException e) {
                Log.e("pokedroid",e.toString());
            }
        }
        return true;
    }

    protected void onProgressUpdate(Integer...integers)
    {
        p.setMessage("Downloading update...\n"+integers[0]/1000+"kb downloaded so far.");
    }

    protected void onPostExecute(Boolean b)
    {
        if(b==null)
        {
            noConnection.show();
            deleteFile("PokeDroid.apk");
            p.dismiss();
            return;
        }
        if(!b)
            noNewUpdate.show();
        else
        {
            Intent intent=new Intent();
            intent.setAction(android.content.Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse("file:///data/data/com.games.pokedroid/files/PokeDroid.apk"), "application/vnd.android.package-archive");
            startActivity(intent);
            deleteFile("PokeDroid.apk");
        }
        p.dismiss();
    }

    public void saveObject(String obj, String filename) throws IOException
    {
        FileOutputStream fos = openFileOutput(filename,Context.MODE_PRIVATE);
        ObjectOutputStream out = new ObjectOutputStream(fos);
        out.writeObject(obj);
        out.close();
        fos.close();
    }

    public String loadObject(String filename) throws StreamCorruptedException, IOException, ClassNotFoundException
    {
        FileInputStream fis=openFileInput(filename);
        ObjectInputStream in=new ObjectInputStream(fis);
        String out=(String) in.readObject();
        in.close();
        fis.close();
        return out;
    }
}

This is a subclass in my Activity, of course. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:55:27+00:00Added an answer on May 22, 2026 at 8:55 pm

    I can see one issue in your code:

     startActivity(intent);
     deleteFile("PokeDroid.apk");
    

    This code sends intent and then deletes the file. Note that startActivity is asynchronous function. I.e. it sends the request, but does not wait for completion of that request. So when the intent is actually received by Application Installer Activity (let’s call it that way ) your .apk file has already been deleted by you.

    How to fix:

    You need to replace those two lines of code with:

    startActivityForResult(intent);
    

    And then in onActivityResult function:

    deleteFile("PokeDroid.apk");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a silverlight app (hosted at intranet.mydomain.net) and a WCF service at (webservices.mydomain.net)
I have an ASP.NET MVC app hosted at webhost4life What's a good way to
I have hosted .NET 4.0 / ASP.NET MVC 3 app on IIS 6 on
I have a basic 3 tier app Presentation/Web (ASP.NET MVC) Application Services (WCF, hosted
I have an app where I create many uiviews and add them to the
I have my app hosted in a London Server. I am in Madrid, Spain.
I have a web app hosted in a cloud environment which can be expanded
I have a console app that is calling a WCF app hosted in IIS.
I have just encountered very strange problem - my GWT app hosted on Google
Real World Problem: I have my app hosted on Heroku , who (to my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.