开发者

Android - autoupdate problem

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?


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.


I use this:

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

and it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜