Code Note:
/** * Get the version name of the application sequence * * @return */ PrivateStringGetversionname() {//APK for administrative installation and APK for not installedPackagemanager Packagemanager = Getpackagemanager ();Try{//Get APK function manifest file: To prevent errors directly using the Getpackagename () method to obtain the package name //Packagemanager.getpackageinfo ("Com.xuliugen.mobilesafe", 0);PackageInfo PackageInfo = Packagemanager.getpackageinfo (Getpackagename (),0);//Return version name returnPackageinfo.versionname; }Catch(Namenotfoundexception e) {E.printstacktrace ();return ""; } }
Getpackagemanager () API Description:
Common methods:
publicabstractgetPackageManager() 功能:获得一个PackageManger对象
publicabstractgetApplicationIcon(String packageName)参数: packageName 包名功能:返回给定包名的图标,否则返回null
publicabstract ApplicationInfo flags)参数: packagename 包名 flags 该ApplicationInfo是此flags标记,通常可以直接赋予常数0即可功能:返回该ApplicationInfo对象
publicabstract List<ApplicationInfo> getInstalledApplications(int flags)参数: flag为一般为GET_UNINSTALLED_PACKAGES,那么此时会返回所有ApplicationInfo。我们可以对ApplicationInfo 的flags过滤,得到我们需要的。功能:返回给定条件的所有PackageInfo
publicabstract List<PackageInfo> getInstalledPackages(int flags) 参数如上功能:返回给定条件的所有PackageInfo
public abstractResolveInfo resolveActivityint flags)参数: intent 查寻条件,Activity所配置的action和category flags: MATCH_DEFAULT_ONLY :Category必须带有CATEGORY_DEFAULT的Activity,才匹配 GET_INTENT_FILTERS :匹配Intent条件即可 GET_RESOLVED_FILTER :匹配Intent条件即可功能 :返回给定条件的ResolveInfo对象(本质上是Activity)
publicabstract List<ResolveInfo> queryIntentActivitiesint flags)参数同上功能 :返回给定条件的所有ResolveInfo对象(本质上是Activity),集合对象
publicabstract ResolveInfo resolveServiceint flags)参数同上功能 :返回给定条件的ResolveInfo对象(本质上是Service)
publicabstractqueryIntentServicesint flags)参数同上功能 :返回给定条件的所有ResolveInfo对象(本质上是Service),集合对象
PackageInfo class
Description: Obtain the information for the Androidmanifest.xml file manually.
Characters commonly used segment:
publicString packageName 包名public ActivityInfo[] activities 所有<activity>节点信息public ApplicationInfo applicationInfo <application>节点信息,只有一个public ActivityInfo[] receivers 所有<receiver>节点信息,多个public ServiceInfo[] services 所有<service>节点信息 ,多个
Packageiteminfo class
Description: The base class for all nodes in the Androidmanifest.xml file provides basic information about these nodes: label, icon, Meta-data. It does not
Directly, but inherits from the subclass and then calls the appropriate method.
ApplicationInfo class inherits from Packageiteminfo
Description: Gets information about a node in a specific reference program.
Field Description: Flags field: Flag_system System Application, Flag_external_storage indicates that the app is installed in SDcard
Common methods are inherited to LoadIcon () and Loadlabel () in the Packageiteminfo class
Activityinfo class inherits from Packageiteminfo
Description: Gets information about the application or node. We can use it to get any properties we set, including
Theme, Launchmode, Launchmode, etc.
Common methods are inherited to LoadIcon () and Loadlabel () in the Packageiteminfo class
ServiceInfo class
Description: Similar to Activityinfo, it also inherits from Packageiteminfo, except that it represents the node information.
Resolveinfo class
Description: Gets information about its previous level of directory according to the node, typically, node information.
How to get the Android project for Versionname Getpackagemanager ()