Android中的程序安装和卸载
16lz
2021-01-26
在Android应用开发中我们经常会用到程序的安装和卸载,比如说程序的升级,在程序中管理一些应用等等。下面就写一些关于安装和卸载的东东。
安装应用程序:
File f = new File(Environment.getExternalStorageDirectory() + File.separator + fileName); // apk所在的路径// 安装应用程序Intent installIntent = new Intent();installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);installIntent.setAction(android.content.Intent.ACTION_VIEW);installIntent.setDataAndType(Uri.fromFile(f), "application/vnd.android.package-archive");startActivity(installIntent);
卸载应用程序:
Uri packageURI = Uri.parse("package:com.android.tonysun.myapplication"); // 应用的包名 Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI); startActivity(uninstallIntent);
另外,下面这段代码是获得设备中所有的包名:
List<PackageInfo> packages = context.getPackageManager() .getInstalledPackages(0);
希望能够给用得着的朋友有所帮助!
更多相关文章
- CommonsWare Android(安卓)Components
- Flash移动开发高级教程——创建Anroid & iPhone应用
- Android中如何获取系统中所有的应用程序
- phonegap WebApp
- android sdk和ndk开发环境搭建
- Android开发者指南(18) ―― Web Apps Overview
- Android开发准备——Java和Android(安卓)Studio环境搭建
- unity3d发布Android程序
- android开发环境搭建--android studio安装与配置