Applications related to packageinfo

Source: Internet
Author: User
First, let's take a look at packageiteminfo, which is a base class containing some information. Its direct subclasses include applicationinfo, componentinfo, instrumentationinfo, permissiongroupinfo, and permissioninfo. Its indirect subclasses include activityinfo, providerinfo, and serviceinfo. The information contained in this class is equal for all projects in the package. These packages are held by the Package Manager. This class provides basic attributes: Label, icon, and meta-data. This class is not intended to be called by itself. It simply shares common definitions between all items returned by the Package Manager. For example, it does not implement the parcelable interface, but it helps implement the parcelable subclass and provides a convenient method. Applicationinfo is the information obtained from a specific application. This information is collected from the <Application> tag of androdimanifest. xml. The resolveinfo class is obtained by parsing the intent corresponding to the intentfilter. It partially corresponds to the information collected from the <intent> tag of androidmanifest. xml. The packagemanager class is used to return information about packages associated with Applications Currently mounted to the device. You can get this class through getpacagemanager. Applicationinfo compared with resolveinfo: the former can obtain the icon, label, meta-data, and description. The latter can only get the icon and label. 1. packagemanager: packagemanager = This. getpackagemanager (); List <packageinfo> packageinfolist = packagemanager. getinstalledpackages (0); you can use the preceding method to obtain all applications installed on your mobile phone. Program Including information about manually installed APK packages and pre-installed application software. to distinguish between these two types of software, you can use the following methods:. packageinfo obtained from packageinfolist, and then through packageinfo. applicationinfo gets applicationinfo. B. determine the value of (applicationinfo. Flags & applicationinfo. flag_system). If the value is greater than 0, the obtained application is a pre-installed application, and vice versa. C. Determine the detachable application (appinfo. Flags & applicationinfo. flag_updated_system_app )! = 0 | (appinfo. flags & applicationinfo. flag_system) = 0) 2. Obtain the image, application name, and package name: packagemanager. getapplicationicon (pinfo. applicationinfo); // iconpackagemanager. getapplicationlabel (pinfo. applicationinfo ). tostring () // Application name pinfo. applicationinfo. packagename // package name 3 obtains a set of shared applications: /*** query all apps that support sharing on the mobile phone * @ Param context * @ return */public static list <resolveinfo> getmediaapps (context) {list <resolveinfo> Mapp S = new arraylist <resolveinfo> (); intent = new intent (intent. action_send, null); intent. addcategory (intent. category_default); intent. settype ("text/plain"); packagemanager pmanager = context. getpackagemanager (); mapps = pmanager. queryintentactivities (intent, packagemanager. component_enabled_state_default); Return mapps;} because of this method, the returned packageinfo object is not. But resolveinfo. Therefore, the methods for obtaining images, application names, and package names are different: View plaincopy to clipboardprint? Packagemanager pmanager = messagesendactivity. this. getpackagemanager (); /******************** query all apps that support sharing on the mobile phone ********** * *********/list <resolveinfo> resolvelist = utils. getmediaapps (messagesendactivity. this); For (INT I = 0; I <resolvelist. size (); I ++) {resolveinfo resolve = resolvelist. get (I); incluiteminfo items item = new incluiteminfo (); // custom class // set icon items item. seticon (resolve. loadicon (pmanager) ); // Set Application name using item. setlabel (resolve. loadlabel (pmanager ). tostring (); // set package name into item. setpackagename (resolve. activityinfo. packagename);} 4 how to obtain the application permission: packagemanager. getpackageinfo (packagename, packagemanager. get_permissions ). requestedpermissions5 call the system program setting interface 1) 2.3 or above system intent = new intent (settings. action_application_details_settings); Uri uri = Uri. fromparts (SChE Me, packagename, null); intent. setdata (URI); startactivity (intent); 2) 2.2, 2.1 private void startapplicationdetailsactivity () {intent I = new intent (intent. action_view); I. setclassname ("com. android. settings "," com. android. settings. installedappdetails "); I. putextra (app_pkg_name, packagename); startactivity (I) ;}but the definition of the constant app_pkg_name is different. 2.2 is defined as "PKG", 2.1 is defined as "com. Android. settings. applicationpkgname" 3) General Code Private Static final string scheme = "package";/*** call the extra name required for the system installedappdetails interface (for Android 2.1 and earlier versions) */Private Static final string app_pkg_name_21 = "com. android. settings. applicationpkgname ";/*** extra name required to call the system installedappdetails interface (for Android 2.2) */Private Static final string app_pkg_name_22 =" PKG "; /*** name of the package where installedappdetails is located */Private Static final string app_details_package_na Me = "com. android. settings ";/*** installedappdetails class name */Private Static final string app_details_class_name =" com. android. settings. installedappdetails ";/*** call the installedappdetails interface to display the details of the installed application. For Android 2.3 (API level * 9) and later, use the interfaces provided by the SDK; for Android 2.3 or earlier, use non-public interfaces (view the installedappdetails source code ). ** @ Param context ** @ Param packagename * package name of the application */public static void showinstalledappdetails (context, string packagename) {intent = new intent (); final int apilevel = build. version. sdk_int; If (apilevel> = 9) {// 2.3 (apilevel 9) or above, use the SDK-provided interface intent. setaction (settings. action_application_details_settings); Uri uri = Uri. fromparts (scheme, packagename, null); intent. setdata (URI );} In else {// below 2.3, The app_pkg_name used by installedappdetails is different from that used in non-public interfaces (view the source code of installedappdetails) // 2.2 and 2.1. Final string apppkgname = (apilevel = 8? App_pkg_name_22: app_pkg_name_21); intent. setaction (intent. action_view); intent. setclassname (app_details_package_name, app_details_class_name); intent. putextra (apppkgname, packagename);} context. startactivity (intent);} 6 get the uninstalled APK icon http://blog.csdn.net/sodino/archive/2011/03/01/6215224.aspx7 listen to whether the Android app is uninstalled successfully http://hi.baidu.com/luodaijun/blog/item/0887a8c37e9dfc58b219a808.html8 install APK intent I Ntent = new intent (intent. action_view); intent. setdataandtype (URI. fromfile (new file ("/sdcard/1.apk")," application/vnd. android. package-Archive "); startactivity (intent); 9 to run an app first, Android has a packagemanager. This feature is very powerful, and its function is the same as what it means. Suppose: if we know the package name and activity name of a third-party application, and whether it can be started, the answer is to let the city "yes" start code: packagemanager PM; // initialize pm, for example, in the activity, you can packagemanager PM = getpackagemanager (); packageinfo Pi = PM. getpac Kageinfo ("package name", packagemanager. get_activities); // packageinfo contains a wealth of package information, what is the 'package name', in androidmanifest. clearly defined in XML // For example, package = "XXX. YYY. portal. ui "activityinfo AI = pi. activities [0]; // activityinfo. Similarly, this is the activity information. // here, it points to the activity in the first package. Most of them are the first activity. If (AI = NULL) throw new exception (PKG + "does not contain any activity"); string sname = AI. name; // here we get the activity class name to start it: intent = new intent (); In Tent. setcomponent (New componentname (PKG, sname); parent. startactivity (intent); 10 get the package name of a third-party application to start the activity as long as there is a package name, but I don't know the name. What should I do? If the application cannot be started without installation, you can install it. Method 1: mybroadcastreceiver myreceiver = new mybroadcastreceiver (); intentfilter filter = new intentfilter (intent. action_package_install); filter. addaction (intent. action_package_added); filter. adddatascheme ("package"); registerreceiver (myreceiver, filter); monitors installation. In the onreceive function of mybroadcastreceiver, public void onreceive (context arg0, intent) {string spackagename = intent. getdatastring (); // This is the package name}. You can also use androidmanifest. xml configuration to monitor method 2: Enumerate all installed applications and filter out the public abstract list <packageinfo> getinstalledpackages (INT flags) of packagemanager based on your own conditions to obtain the list of installed applications.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.