`
gybin
  • 浏览: 268990 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

几个Info系列的类的总结

 
阅读更多

 

首先我们来看一下PackageItemInfo,它是包含了一些信息的基类,它的直接子类有:ApplicationInfoComponentInfoInstrumentationInfoPermissionGroupInfoPermissionInfo。它的间接子类有:ActivityInfoProviderInfoServiceInfo。这个类包含的信息对于所有包中项目是平等的。

public class

PackageItemInfo

extends Object
java.lang.Object
   ↳ android.content.pm.PackageItemInfo
Known Direct Subclasses
Known Indirect Subclasses

 

这些Package items是被Package manager所持有的。这个类提供了属性的非常普通的基本设置:labeliconmeta-data。这个类的意图不是被自己调用。它在这只是简单地分享被package manager返回的所有items之间的普通定义。比如,它自己并不实现Parcelable接口,但却帮助实现了Parcelable的子类提供了方便的方法。

   ApplicationInfo是从一个特定的应用得到的信息。这些信息是从相对应的Androdimanifest.xml<application>标签中收集到的。

   ResolveInfo这个类是通过解析一个与IntentFilter相对应的intent得到的信息。它部分地对应于从AndroidManifest.xml<intent>标签收集到的信息。

  PackageManager这个类是用来返回各种的关联了当前已装入设备了的应用的包的信息。你可以通过getPacageManager来得到这个类。

  ApplicationInfoResolveInfo比较:前者能够得到IconLabelmeta-datadescription。后者只能得到IconLabel

  下面讲一下这几个类综合在一起的具体应用:

  通过调用PackageManager的方法可以得到两种不同的信息:

  首先要得到manager:

PackageManager manager = getPackageManager();

  方法一:

List<ApplicationInfo> appList = manager.getInstalledApplications(PackageManager.GET.UNINSTALLED_PAKAGES);

  它是通过解析AndroidManifest.xml<application>标签中得到的,所以它能得到所有的app

  方法二:

Intent intent = new Intent(Intent.A CTION_MAIN,null);

intent.addCategory(Intent.CATEGORY_LAUNCHER);

List<ResolveInfo> appList = manager.queryIntentActivities(intent,0);

  它是通过解析<Intent-filter>标签得到有

<action android:name=”android.intent.action.MAIN”/>

<action android:name=”android.intent.category.LAUNCHER”/>

  这样的app,所以得到的要比第一种方法少(前者比它多那种servicepreviderapp

 

public class

PackageInfo

extends Object
implements Parcelable
java.lang.Object
   ↳ android.content.pm.PackageInfo
Fields
public ActivityInfo[] activities  Array of all <activity> tags included under <application>, or null if there were none.
public ApplicationInfo

applicationInfo 

应用程序

Information collected from the <application> tag, or null if there was none.
public ConfigurationInfo[] configPreferences Application specified preferred configuration <uses-configuration> tags included under <manifest>, or null if there were none.
public int[] gids All kernel group-IDs that have been assigned to this package.
public InstrumentationInfo[] instrumentation Array of all <instrumentation> tags included under <manifest>, or null if there were none.
public String packageName  包名 The name of this package.
public PermissionInfo[] permissions Array of all <permission> tags included under <manifest>, or null if there were none.
public ProviderInfo[] providers Array of all <provider> tags included under <application>, or null if there were none.
public ActivityInfo[] receivers Array of all <receiver> tags included under <application>, or null if there were none.
public FeatureInfo[] reqFeatures The features that this application has said it requires.
public String[] requestedPermissions Array of all <uses-permission> tags included under <manifest>, or null if there were none.
public ServiceInfo[] services Array of all <service> tags included under <application>, or null if there were none.
public String sharedUserId The shared user ID name of this package, as specified by the <manifest> tag's sharedUserId attribute.
public int sharedUserLabel The shared user ID label of this package, as specified by the <manifest> tag's sharedUserLabel attribute.
public Signature[] signatures Array of all signatures read from the package file.
public int versionCode   版本号 The version number of this package, as specified by the <manifest> tag's versionCode attribute.
public String versionName 版本名 The version name of this package, as specified by the <manifest> tag's versionName attribute.

 

public class

ApplicationInfo

extends PackageItemInfo
implements Parcelable
java.lang.Object
   ↳ android.content.pm.PackageItemInfo
     ↳ android.content.pm.ApplicationInfo

 

public String backupAgentName Class implementing the Application's backup functionality.
public String className Class implementing the Application object.
public String dataDir Full path to a directory assigned to the package for its persistent data.
public int descriptionRes A style resource identifier (in the package's resources) of the description of an application.
public boolean enabled When false, indicates that all components within this application are considered disabled, regardless of their individually set enabled status.
public int flags Flags associated with the application.
public String manageSpaceActivityName Class implementing the Application's manage space functionality.
public String permission Optional name of a permission required to be able to access this application's components.
public String processName The name of the process this application should run in.
public String publicSourceDir Full path to the location of the publicly available parts of this package (i.e.
public String[] sharedLibraryFiles Paths to all shared libraries this application is linked against.
public String sourceDir Full path to the location of this package.
public int targetSdkVersion The minimum SDK version this application targets.
public String taskAffinity Default task affinity of all activities in this application.
public int theme A style resource identifier (in the package's resources) of the default visual theme of the application.
public int uid The kernel user-ID that has been assigned to this application; currently this is not a unique ID (multiple applications can have the same uid).
Public Methods
int describeContents()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
void dump(Printer pw, String prefix)
CharSequence loadDescription(PackageManager pm)
Retrieve the textual description of the application.
String toString()
Returns a string containing a concise, human-readable description of this object.
void writeToParcel(Parcel dest, int parcelableFlags)

 

Inherited Methods
 From class android.content.pm.PackageItemInfo
void dumpBack(Printer pw, String prefix)
void dumpFront(Printer pw, String prefix)
Drawable loadIcon(PackageManager pm)
Retrieve the current graphical icon associated with this item.  加载图标
CharSequence loadLabel(PackageManager pm)
Retrieve the current textual label associated with this item. 加载标签名字
XmlResourceParser loadXmlMetaData(PackageManager pm, String name)
Load an XML resource attached to the meta-data of this item.
void writeToParcel(Parcel dest, int parcelableFlags)

 

 

public abstract class

PackageManager

extends Object
java.lang.Object
   ↳ android.content.pm.PackageManager
Known Direct Subclasses

 

 

Public Methods
abstract void addPackageToPreferred(String packageName)
This method is deprecated. This function no longer does anything; it was an old approach to managing preferred activities, which has been superceeded (and conflicts with) the modern activity-based preferences.
abstract boolean addPermission(PermissionInfo info)
Add a new dynamic permission to the system.
abstract boolean addPermissionAsync(PermissionInfo info)
Like addPermission(PermissionInfo) but asynchronously persists the package manager state after returning from the call, allowing it to return quicker and batch a series of adds at the expense of no guarantee the added permission will be retained if the device is rebooted before it is written.
abstract void addPreferredActivity(IntentFilter filter, int match, ComponentName[] set, ComponentName activity)
This method is deprecated. This is a protected API that should not have been available to third party applications. It is the platform's responsibility for assigning preferred activities and this can not be directly modified. Add a new preferred activity mapping to the system. This will be used to automatically select the given activity component when Context.startActivity() finds multiple matching activities and also matches the given filter.
abstract String[] canonicalToCurrentPackageNames(String[] names)
Map from a packages canonical name to the current name in use on the device.
abstract int checkPermission(String permName, String pkgName)
Check whether a particular package has been granted a particular permission.
abstract int checkSignatures(String pkg1, String pkg2)
Compare the signatures of two packages to determine if the same signature appears in both of them.
abstract int checkSignatures(int uid1, int uid2)
Like checkSignatures(String, String), but takes UIDs of the two packages to be checked.
abstract void clearPackagePreferredActivities(String packageName)
Remove all preferred activity mappings, previously added with addPreferredActivity(IntentFilter, int, ComponentName[], ComponentName), from the system whose activities are implemented in the given package name.
abstract String[] currentToCanonicalPackageNames(String[] names)
Map from the current package names in use on the device to whatever the current canonical name of that package is.
abstract Drawable getActivityIcon(Intent intent)
Retrieve the icon associated with an Intent.
abstract Drawable getActivityIcon(ComponentName activityName)
Retrieve the icon associated with an activity.
abstract ActivityInfo getActivityInfo(ComponentName className, int flags)
Retrieve all of the information we know about a particular activity class.
abstract List<PermissionGroupInfo> getAllPermissionGroups(int flags)
Retrieve all of the known permission groups in the system.
abstract int getApplicationEnabledSetting(String packageName)
Return the the enabled setting for an application.
abstract Drawable getApplicationIcon(String packageName)
Retrieve the icon associated with an application.   获取程序图标
abstract Drawable getApplicationIcon(ApplicationInfo info)
Retrieve the icon associated with an application.
abstract ApplicationInfo getApplicationInfo(String packageName, int flags)
Retrieve all of the information we know about a particular package/application.
abstract CharSequence getApplicationLabel(ApplicationInfo info)
Return the label to use for this application.   获取程序描述
abstract int getComponentEnabledSetting(ComponentName componentName)
Return the the enabled setting for a package component (activity, receiver, service, provider).
abstract Drawable getDefaultActivityIcon()
Return the generic icon for an activity that is used when no specific icon is defined.
abstract Drawable getDrawable(String packageName, int resid, ApplicationInfo appInfo)
Retrieve an image from a package.
abstract List<ApplicationInfo> getInstalledApplications(int flags)
Return a List of all application packages that are installed on the device.  获取所有已安装程序信息
abstract List<PackageInfo> getInstalledPackages(int flags)
Return a List of all packages that are installed on the device.    获取所有已安装 程序的包信息
abstract String getInstallerPackageName(String packageName)
Retrieve the package name of the application that installed a package.
abstract InstrumentationInfo getInstrumentationInfo(ComponentName className, int flags)
Retrieve all of the information we know about a particular instrumentation class.
abstract Intent getLaunchIntentForPackage(String packageName)
Return a "good" intent to launch a front-door activity in a package, for use for example to implement an "open" button when browsing through packages.
abstract String getNameForUid(int uid)
Retrieve the official name associated with a user id.
PackageInfo getPackageArchiveInfo(String archiveFilePath, int flags)
Retrieve overall information about an application package defined in a package archive file
abstract int[] getPackageGids(String packageName)
Return an array of all of the secondary group-ids that have been assigned to a package.
abstract PackageInfo getPackageInfo(String packageName, int flags)
Retrieve overall information about an application package that is installed on the system.
abstract String[] getPackagesForUid(int uid)
Retrieve the names of all packages that are associated with a particular user id.
abstract PermissionGroupInfo getPermissionGroupInfo(String name, int flags)
Retrieve all of the information we know about a particular group of permissions.
abstract PermissionInfo getPermissionInfo(String name, int flags)
Retrieve all of the information we know about a particular permission.
abstract int getPreferredActivities(List<IntentFilter> outFilters, List<ComponentName> outActivities, String packageName)
Retrieve all preferred activities, previously added with addPreferredActivity(IntentFilter, int, ComponentName[], ComponentName), that are currently registered with the system.
abstract List<PackageInfo> getPreferredPackages(int flags)
Retrieve the list of all currently configured preferred packages.
abstract ActivityInfo getReceiverInfo(ComponentName className, int flags)
Retrieve all of the information we know about a particular receiver class.
abstract Resources getResourcesForActivity(ComponentName activityName)
Retrieve the resources associated with an activity.
abstract Resources getResourcesForApplication(ApplicationInfo app)
Retrieve the resources for an application.
abstract Resources getResourcesForApplication(String appPackageName)
Retrieve the resources associated with an application.
abstract ServiceInfo getServiceInfo(ComponentName className, int flags)
Retrieve all of the information we know about a particular service class.
abstract FeatureInfo[] getSystemAvailableFeatures()
Get a list of features that are available on the system.
abstract String[] getSystemSharedLibraryNames()
Get a list of shared libraries that are available on the system.
abstract CharSequence getText(String packageName, int resid, ApplicationInfo appInfo)
Retrieve text from a package.
abstract XmlResourceParser getXml(String packageName, int resid, ApplicationInfo appInfo)
Retrieve an XML file from a package.
abstract boolean hasSystemFeature(String name)
Check whether the given feature name is one of the available features as returned by getSystemAvailableFeatures().
abstract boolean isSafeMode()
Return whether the device has been booted into safe mode.
abstract List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags)
Retrieve all receivers that can handle a broadcast of the given intent.
abstract List<ProviderInfo> queryContentProviders(String processName, int uid, int flags)
Retrieve content provider information.
abstract List<InstrumentationInfo> queryInstrumentation(String targetPackage, int flags)
Retrieve information about available instrumentation code.
abstract List<ResolveInfo> queryIntentActivities(Intent intent, int flags)
Retrieve all activities that can be performed for the given intent.
abstract List<ResolveInfo> queryIntentActivityOptions(ComponentName caller, Intent[] specifics, Intent intent, int flags)
Retrieve a set of activities that should be presented to the user as similar options.
abstract List<ResolveInfo> queryIntentServices(Intent intent, int flags)
Retrieve all services that can match the given intent.
abstract List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
Query for all of the permissions associated with a particular group.
abstract void removePackageFromPreferred(String packageName)
This method is deprecated. This function no longer does anything; it was an old approach to managing preferred activities, which has been superceeded (and conflicts with) the modern activity-based preferences.
abstract void removePermission(String name)
Removes a permission that was previously added with addPermission(PermissionInfo).
abstract ResolveInfo resolveActivity(Intent intent, int flags)
Determine the best action to perform for a given Intent.
abstract ProviderInfo resolveContentProvider(String name, int flags)
Find a single content provider by its base path name.
abstract ResolveInfo resolveService(Intent intent, int flags)
Determine the best service to handle for a given Intent.
abstract void setApplicationEnabledSetting(String packageName, int newState, int flags)
Set the enabled setting for an application This setting will override any enabled state which may have been set by the application in its manifest.
abstract void setComponentEnabledSetting(ComponentName componentName, int newState, int flags)
Set the enabled setting for a package component (activity, receiver, service, provider).

 

 

FROM:http://www.androidsnippets.org/snippets/70/

 

Java代码 
  1. class PInfo {    
  2.     private String appname = "";    
  3.     private String pname = "";    
  4.     private String versionName = "";    
  5.     private int versionCode = 0;    
  6.     private Drawable icon;    
  7.     private void prettyPrint() {    
  8.         log(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode + "\t");    
  9.     }    
  10. }    
  11.     
  12. private void listPackages() {    
  13.     ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */    
  14.     final int max = apps.size();    
  15.     for (int i=0; i<max; i++) {    
  16.         apps.get(i).prettyPrint();    
  17.     }    
  18. }    
  19.     
  20. private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {    
  21.     ArrayList<PInfo> res = new ArrayList<PInfo>();            
  22.     List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);    
  23.     for(int i=0;i<packs.size();i++) {    
  24.         PackageInfo p = packs.get(i);    
  25.         if ((!getSysPackages) && (p.versionName == null)) {    
  26.             continue ;    
  27.         }    
  28.         PInfo newInfo = new PInfo();    
  29.         newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();    
  30.         newInfo.pname = p.packageName;    
  31.         newInfo.versionName = p.versionName;    
  32.         newInfo.versionCode = p.versionCode;    
  33.         newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());    
  34.         res.add(newInfo);    
  35.     }    
  36.     return res;     
  37. }    

获取未安装的APK信息

java代码 
  1. /** 获取未安装的APK信息 
  2.      * @param context 
  3.      * @param archiveFilePath APK文件的路径。如:/sdcard/download/XX.apk 
  4.      */  
  5.     public void getUninatllApkInfo(Context context, String archiveFilePath){  
  6.         PackageManager pm = context.getPackageManager();  
  7.         PackageInfo info = pm.getPackageArchiveInfo(archiveFilePath, PackageManager.GET_ACTIVITIES);  
  8.         if(info != null){  
  9.             ApplicationInfo appInfo = info.applicationInfo;  
  10.             String appName = pm.getApplicationLabel(appInfo).toString();  
  11.             String packageName = appInfo.packageName;  
  12.             Drawable icon = pm.getApplicationIcon(appInfo);  
  13.         }  
  14.     }  

 

据测试:无法获取未安装APK的图片。

分享到:
评论

相关推荐

    TTL74系列芯片总结

    TTL74系列芯片总结 TTL74系列芯片是目前最常用的数字电路芯片系列之一,包含了逻辑门、触发器、计数器、译码器、加法器、寄存器等多种类型的芯片。这些芯片广泛应用于数字电路设计、计算机系统、通信系统、自动控制...

    缤纷系列第二卷——商务总结报告工作汇报类动态ppt模板.rar

    制作高质量的商务PPT时,有以下几个关键知识点: 1. **设计原则**:模板遵循了设计的基本原则,如平衡、对比、对齐和重复,确保视觉效果整洁且引人注目。颜色选择上,"缤纷系列"可能包含多种色调,但它们通常会协调...

    74系列集成电路的分类及特性.pdf

    选择合适的74系列集成电路时,需要考虑以下几个方面: 1. **供电电压**:根据实际应用中的电源电压选择合适的集成电路。例如,如果供电电压为3V,则可以选择74HC系列的产品。 2. **功耗需求**:对于便携式设备或...

    面试问题总结-关于YOLO系列(一)这是一份总结YOLO系列目标检测算法的面试问题.md

    主要包括以下几个方面: 1. 简要介绍了YOLO算法提出的背景,传统的滑窗检测和区域检测算法的缺院。 2. 阐述了YOLO v1的算法思想,将目标检测问题转化为回归问题,在训练和预测阶段的原理。并解释了非极大值抑制(NMS)的...

    Java集合类总结

    ### Java集合类总结 #### 一、概述 Java集合类框架是Java标准库的一个重要组成部分,主要用于存储和处理数据集合。这些集合类被定义在`java.util`包中,为开发者提供了灵活的数据结构来实现各种应用程序的需求。...

    安全生产月系列活动总结.doc

    以下是活动的几个关键点: 1. **安全知识有奖竞赛文艺晚会**:这个活动是通过举办晚会的形式,以安全知识竞赛为主题,吸引员工广泛参与。通过网络媒体、宣传橱窗和横幅等渠道进行大规模宣传,旨在普及安全生产法规...

    深入理解Apache_Mina_(1)----_Mina的几个类

    ### 深入理解 Apache Mina (1) —— Mina 的几个核心类 #### 一、Mina 核心类概述 Mina (Multi-threaded Integrated Network Architecture) 是一个高性能且灵活的网络应用程序框架,它支持多种传输协议,如 TCP、...

    c++概念复习总结

    从给出的文件内容中,我们可以总结出以下几个重要的C++基本概念知识点: 1. 引用的定义与使用 在C++中,引用是一种数据类型,用于为对象创建一个别名。它允许不同的变量名引用同一块数据,而不需要额外的内存空间来...

    朦胧背景简约欧美范iOS系列工作总结报告ppt模板.zip

    这个模板的特点和知识点主要集中在以下几个方面: 1. **iOS风格**:iOS风格通常指的是苹果公司的设计语言,它强调简洁、直观和一致性。在PPT模板中,这种风格体现在了整体设计的清晰度、色彩搭配以及图标和元素的...

    程序员年终总结PPT模板

    基于“年终总结”和“PPT”的标签,我们可以推测这个模板集将涵盖以下几点关键知识点: 1. **结构规划**:一个良好的年终总结PPT应该有清晰的结构,包括开场页、目录、工作概述、项目详情、技术提升、团队合作、...

    “全国安全生产月”活动总结 是全国第几个安全生产月.doc

    文章提到的20XX年是全国第几个安全生产月,具体数字未给出,但可以看出该活动已经形成了一种持续的传统,每年都会进行。 在活动的组织上,公司通常会成立专门的领导小组,如文中提到的xxxx"全国安全生产月"活动领导...

    爱建证券_20161128_多因子系列之二,成长类因子初测.pdf

    《多因子系列之二:成长类因子初测》通过对成长类因子的深入分析,为投资者提供了一个了解不同成长类因子如何影响股票表现的机会。这份报告不仅涵盖了理论背景,还提供了实际测试结果,有助于投资者更好地理解成长类...

    【酒店类】人力资源部工作总结与工作计划.doc

    【酒店类】人力资源部工作总结与工作计划主要涵盖了以下几个方面的知识点: 1. **人事管理**: - 20xx年酒店员工总数为311人,包括16名经理及以上管理层,295名主管及以下员工,全年离职256人,员工在岗率为55%,...

    汇报总结—23财税相关资料系列.pptx

    在23财税相关资料系列的汇报总结中,我们主要关注以下几个关键领域:工作回顾、心得体会、经验教训以及新年计划。这些部分涵盖了财务管理和税务操作的基础要点,对于理解和提升个人或企业的财税管理水平至关重要。 ...

    典雅尊贵荷花金鱼中国风系列工作总结PPT模板.pptx

    创建一份典雅尊贵的荷花金鱼中国风系列工作总结PPT模板,需要关注以下几个关键设计元素: 1. **主题选择**:荷花和金鱼是中国传统文化中的吉祥象征,寓意纯洁高雅与富贵吉祥。在设计时,应以这两种元素为主题,通过...

    汇报总结—43财税相关资料系列.pptx

    这份总结报告的结构清晰,分为几个关键部分: 1. 年度工作概述:这部分是对过去一年整体工作的概览,包括了年度目标的完成情况,团队建设的完善,以及工作能力的提升等方面。每个部分都有预留的文本框,供添加具体...

    2016年度工作总结计划ppt模板

    在制作年度工作总结计划PPT时,有以下几个关键知识点: 1. **结构化内容**:一个有效的PPT应有清晰的结构,包括引言(介绍背景和目标)、工作回顾(详述过去一年的主要任务与成就)、问题分析(识别挑战和困难)、...

    年中年终工作总结模板 (125).pptx

    工作总结通常包含以下几个关键部分: 1. **活动方案**:这是对工作计划的概述,包括活动的时间框架,例如12.15至2.20日。这有助于确定总结的范围和时间段。 2. **目录**:列出各个主题,确保涵盖所有重要的工作...

Global site tag (gtag.js) - Google Analytics