android 调用安装界面

来源:互联网 发布:壁虎java 编辑:程序博客网 时间:2024/06/11 18:29
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

intent.setAction(android.content.Intent.ACTION_VIEW);

/* 调用getMIMEType()来取得MimeType */

String type = "application/vnd.android.package-archive";

/* 设置intent的file与MimeType */
intent.setDataAndType(Uri.parse("file://" + apkPath), type);
/*
* 经过实验,发现无论是否成功安装,该Intent都返回result为0 具体结果如下: type requestCode
* resultCode data 取消安装 10086 0 null 覆盖安装 10086 0 null 全新安装 10086 0
* null
*/
context.startActivity(intent);
原创粉丝点击