美文网首页Unity跨平台技术分享
unity 代码安装Android apk

unity 代码安装Android apk

作者: 自由的天空 | 来源:发表于2016-06-23 17:45 被阅读949次

android 在代码中安装apk的方法

第一步:保存apk文件到sdcard或者其他地方

第二步:修改apk文件的权限为可执行 ,例如chmod ‘777’ file:

String command = "chmod " + permission + " " + path;
Runtime runtime = Runtime.getRuntime();
runtime.exec(command);

第三步:使用Intent 调用安装:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.parse("file://" + path),"application/vnd.android.package-archive");
context.startActivity(intent);

相关文章

网友评论

    本文标题:unity 代码安装Android apk

    本文链接:https://www.haomeiwen.com/subject/ktqodttx.html