This blog does not write the API usage only to analyze the knowledge points of this parameter.
Today learning Android suddenly learned to Getinstalledpackages () method to get to install the application information, he received an int flags value, and then on the Internet to query the data is set int value to 0, such as
Packagemanager manager = Context.getpackagemanager ();//Manager to get the package
list<packageinfo> installedpackages = manager.getinstalledpackages (0);
I would like to see the source code to see what the 0 parameters. The result is a problem, the parameters are as follows
public static final int get_activities = 0x00000001;
public static final int get_receivers = 0x00000002;
public static final int get_services = 0x00000004;
public static final int get_providers = 0x00000008;
... 0x00000010
0x00000020
0x00000040
0x00000040
0x00000080
0x00000100
0x00000200
0x00000400
0x00000800
0x00001000
0x00002000
0x00004000;
the meaning of each flag parameter, see the idea is used to get the corresponding package information, all is 16 binary representation of the number of int. But doubts no 0, online query no corresponding information, in this thinking for a long time left the impression of notes.
By observing the source code to help me analyze the information as follows:
(1) Observe the source code comment flags Additional option flags. Use any combination of .... flag
Method Contextual: Additional information is obtained through flag, using any combination of flag.
See this source code combination (combination) Two words actually solved half of the problem. This means that you can combine any flag to add any flag to the parameter;
(2) The value of the static final int by observing other parameters
Like what:
public static final int component_enabled_state_enabled = 1;
public static final int component_enabled_state_disabled = 2;
public static final int component_enabled_state_disabled_user = 3;
Why are the 10 binary values set, and see here I think I've solved the problem,
(3) The value of the analysis method parameter is converted to 2;
The following are: 00000001 00000010 00000100 00001000 ....... ..... The advantage of this setting is that any combination of signatures is unique. Do not confuse
For example, 16+8 = 24 24 can only be obtained by this two number in the parameter.
32+2=34
64 +8=72
If flag is processed in decimal 1 and 2,3,4,5,6,7, it is not possible to use this method when the number of methods in the method is a specific number of times, because the computer does not intelligently handle people's needs.
Come to my conclusion as follows:
Parameter 0 means that you do not accept any flag information, and of course you can return some basic package information! , but such as PERMISSIONS ,receivers and so on will not return, if the flag value does not match and the method forcibly gets the corresponding value, the return value is NULL, has been tested
。
Extension: Packagemanager. Get_activities+ Packagemanager. The get_activities equals 3, and the parameter fills 3 to get the corresponding information for the two flags.
Note the point: Packagemanager. get_activities | Packagemanager. get_activities the same effect as on. As long as there is a 1 in the same position as 1,
All of these are personal views!
Copyright NOTICE: Welcome to reprint, but please bring a link to this blog!
About the analysis of getinstalledpackages parameters.