2

I use this code for saving app.apk from URL:

            Context ctx;
            InputStream input = new BufferedInputStream(url.openStream());

            FileOutputStream output = ctx.getApplicationContext().openFileOutput("myApp.apk", Context.MODE_WORLD_READABLE);

than I save it from input to file by:

        byte data[] = new byte[1024];

        long total = 0;

        while ((count = input.read(data)) != -1) {
            output.write(data, 0, count);
        }

And after downloading, which is successfuly finished now I want to prompt installation - I think I should use FileInputStream, but I don't know exactly how.

After downloading, I have code:

        Intent install=new Intent(Intent.ACTION_VIEW);
        install.setDataAndType(Uri.fromFile(xxx - AND HERE I AM STUCK), "application/vnd.android.package-archive");
        ctx.startActivity(install);

I have tried ctx.getApplicationContext().openFileInput("myApp.apk"), but Uri.fromFile needs file and I am giving it openFileInput. Do you know how to solve it?

Thx

Edit: anyobody knows some some solution?

Waypoint
  • 15,705
  • 36
  • 110
  • 167

2 Answers2

0

I use this:

intent.setDataAndType( Uri.parse("file://" +
    context.getFilesDir().getAbsolutePath() +
    "/" + update_file), ANDROID_PACKAGE);

and it works.

lenik
  • 21,662
  • 4
  • 29
  • 38
0

From: Android Get Application's 'Home' Data Directory

Use getFilesDir() to return the absolute path to where openFileInput saved the file. Then pass this to your File() constructor.

Community
  • 1
  • 1
dev
  • 2,809
  • 5
  • 32
  • 48