Android编程实现任务管理器的方法

  public class TaskInfo {

  Context context ;

  PackageManager pm ;

  public TaskInfo(Context context) {

  this.context = context;

  pm = context.getPackageManager();

  }

  /*

  * 根据包名 查询 图标

  */

  public Drawable getAppIcon(String packname){

  try {

  ApplicationInfo info = pm.getApplicationInfo(packname, 0);

  return info.loadIcon(pm);

  } catch (NameNotFoundException e) {

  // TODO Auto-generated catch block

  e.printStackTrace();

  return null;

  }

  }

  /*

  *获取程序的版本号

  */

  public String getAppVersion(String packname){

  try {

  PackageInfo packinfo = pm.getPackageInfo(packname, 0);

  return packinfo.versionName;

  } catch (NameNotFoundException e) {

  e.printStackTrace();

  return null;

  }

  }

  /*

  * 获取程序的名字

  */

  public String getAppName(String packname){

  try {

  ApplicationInfo info = pm.getApplicationInfo(packname, 0);

  return info.loadLabel(pm).toString();

  } catch (NameNotFoundException e) {

  // TODO Auto-generated catch block

  e.printStackTrace();

  return null;

  }

  }

  /*

  * 获取程序的权限

  */

  public String[] getAppPremission(String packname){

  try {

  PackageInfo packinfo = pm.getPackageInfo(packname, PackageManager.GET_PERMISSIONS);

  //获取到所有的权限

  return packinfo.requestedPermissions;

  } catch (NameNotFoundException e) {

  e.printStackTrace();

  return null;

  }

  }

  /*

  * 获取程序的签名

  */

  public String getAppSignature(String packname){

  try {

  PackageInfo packinfo = pm.getPackageInfo(packname, PackageManager.GET_SIGNATURES);

  //获取到所有的权限

  return packinfo.signatures[0].toCharsString();

  } catch (NameNotFoundException e) {

  e.printStackTrace();

  return null;

  }

  }

  }