发布网友
共2个回答
热心网友
String str = "/appstore.apk";
String fileName = Environment.getExternalStorageDirectory() + str;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)),
"application/vnd.android.package-archive");
startActivity(intent);
这个是安装apk的代码,不过不是静默安装,安装的时候会跟安装一般的软件一样会有提示的str就是apk的路径
热心网友
可以调用系统自带的程序安装器来安装另一个程序,如下:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//filePath为文件路径
intent.setDataAndType(Uri.parse("file://"+filePath), "application/vnd.android.packagearchive");
startActivity(intent);追问我想请问,这个代码里的文件路径是怎么样的格式的
因为我的b.apk是要放在a程序的资源当中的,不能存在手机里或者sd卡里。