欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android根据包名获取程序基本信息

程序员文章站 2022-06-04 15:51:20
...
public class Info {  
    Context context ;  
    PackageManager pm ;  
    public Info(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();  
            
        }  
    }  
      
    /* 
     *获取程序的版本号   
     */  
    public String getAppVersion(String packname){  
          
          try {  
              PackageInfo packinfo = pm.getPackageInfo(packname, 0);  
              return packinfo.versionName;  
            } catch (NameNotFoundException e) {  
                e.printStackTrace();  
                 
            }  
    }  
      
  
    /* 
     * 获取程序的名字  
     */  
    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();  
               
            }  
    }  
    /* 
     * 获取程序的权限 
     */  
    public String[] getAppPremission(String packname){  
          try {  
              PackageInfo packinfo =    pm.getPackageInfo(packname, PackageManager.GET_PERMISSIONS);  
              //获取到所有的权限   
              return packinfo.requestedPermissions;  
  
            } catch (NameNotFoundException e) {  
                e.printStackTrace();  
                 
            }  
    }  
      
      
    /* 
     * 获取程序的签名  
     */  
    public String getAppSignature(String packname){  
          try {  
              PackageInfo packinfo =    pm.getPackageInfo(packname, PackageManager.GET_SIGNATURES);  
              //获取到所有的权限   
              return packinfo.signatures[0].toCharsString();  
  
            } catch (NameNotFoundException e) {  
                e.printStackTrace();  
                
            }  
    }