当前位置: 代码迷 >> Android >> Android中的程序装配和卸载
  详细解决方案

Android中的程序装配和卸载

热度:130   发布时间:2016-05-01 19:22:57.0
Android中的程序安装和卸载

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

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

?

  相关解决方案