android_PackageManager

苏胤
2023-12-01

 

 

  Android获取apk安装包的版本及包名等信息

  String archiveFilePath="sdcard/DangDang.apk";//安装包路径 
  PackageManager pm = getPackageManager();   
  PackageInfo info = pm.getPackageArchiveInfo(archiveFilePath, PackageManager.GET_ACTIVITIES);   
  if(info != null){   
     ApplicationInfo appInfo = info.applicationInfo;   
     String appName = pm.getApplicationLabel(appInfo).toString();   
     String packageName = appInfo.packageName;  //得到安装包名称 
     String version=info.versionName;       //得到版本信息      
     Drawable icon = pm.getApplicationIcon(appInfo);//得到图标信息 
  }

 

 

 

安装:
  String str = "/CanavaCancel.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);
卸载:
  Uri packageURI = Uri.parse("package:com.demo.CanavaCancel");  
  Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);  
  startActivity(uninstallIntent);
  Environment拥有一些可以获取环境变量的方法
  package:com.demo.CanavaCancel 这个形式是 package:程序完整的路径 (包名+程序名).

 

 

 

 

 

 类似资料:

相关阅读

相关文章

相关问答