码迷,mamicode.com
首页 > 移动开发 > 详细

android怎样调出apk安装界面

时间:2016-05-31 12:17:46      阅读:359      评论:0      收藏:0      [点我收藏+]

标签:

开发一个android应用程序,必须有的一个功能就是更新应用的版本。

那么点击更新版本的控件后,应该如何调出apk的安装界面呢?

技术分享

/**
     * 安装程序
     * 
     * @param context    上下文
     * @param file    apk的保存路径
     */
    public static void openFile(Context context, File file) {
        try {
            Intent mIntent = new Intent();
            mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mIntent.setAction(android.content.Intent.ACTION_VIEW);
            mIntent.setDataAndType(Uri.fromFile(file),
                    "application/vnd.android.package-archive");

            context.startActivity(mIntent);

        } catch (Exception e) {
            e.printStackTrace();

            ToastUtils.showToast(
                    context,
                    context.getResources().getString(
                            R.string.toast_openApk_error), false);
        }

    }

 

android怎样调出apk安装界面

标签:

原文地址:http://www.cnblogs.com/wangchaozhangshu/p/5545261.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!