在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);

希望能够给用得着的朋友有所帮助!

更多相关文章

  1. CommonsWare Android(安卓)Components
  2. Flash移动开发高级教程——创建Anroid & iPhone应用
  3. Android中如何获取系统中所有的应用程序
  4. phonegap WebApp
  5. android sdk和ndk开发环境搭建
  6. Android开发者指南(18) ―― Web Apps Overview
  7. Android开发准备——Java和Android(安卓)Studio环境搭建
  8. unity3d发布Android程序
  9. android开发环境搭建--android studio安装与配置

随机推荐

  1. Android(安卓)比Timer更好方法
  2. android webview读取本地相册时“Not all
  3. Android(安卓)访问权限许可大全
  4. Android(安卓)O u-blox gps移植
  5. Android-- 输入法键盘控制
  6. Android(安卓)播放音乐的service
  7. Android(安卓)倒计时控件
  8. httplive流媒体播放(m3u8)
  9. [置顶] android中横竖屏幕的处理
  10. Android读程序包的资源