Android static and dynamic set receiver's android:enabled value

Source: Internet
Author: User

0x 01 Prerequisite constraints:

0x001

static check: refers to using the action to limit intent, and using the Package Manager's Querybroadcastreceivers method, in the Flags field is set to 0 o'clock to find resolveinfo, check the result is that it has no component found .

0x002

dynamic Check: after specifying the package name & Class full pathname form componentname, call the Package Manager's Getcomponentenabledsetting method, get its state value, note that it is an int type, The possible values and meanings are listed below.

0x003

Dynamic Modification: after specifying the package name & Class full pathname componentname, call the Package Manager's Setcomponentenabledsetting method, pass in any one of the following three values, and set the Enabled field.

0x004

Packagemanager.component_enabled_state_default

An Int value of 0 means that the declaration is not displayed in the manifest

Packagemanager.component_enabled_state_enabled

An Int value of 1, which is declared as android:enabled= "true" in manifest

Packagemanager.component_enabled_state_disabled

An Int value of 2, which is declared as android:enabled= "false" in manifest

0x02 Demo Summary of results:

0x001 Use static mode to modify the value of the Enabled field.

0x002 is declared as true|false| default in manifest, its corresponding dynamic check results are 0 (not yet dynamically changed).

0x003 corresponds to a manifest in the display declared as android:enabled= "true", regardless of the dynamic modification of the value (0|1|2), the use of static check is returned true when the dynamic modification of its value is 2 o'clock, the broadcast is not received (0|1) To receive.

0x004 corresponds to the display declared as android:enabled= "false" in manifest, if the program dynamically modifies its value to 1 o'clock, the component can be found with a static check, and its value is still false, but can receive broadcasts, other values ( 0|2), the corresponding component is not found and the broadcast is not received.

0x005 corresponds to no declaration in manifest, the dynamic modification of its value is 2 o'clock, static checks cannot find the corresponding component, and the broadcast, other values (0|1), the static check value is true and can receive broadcasts.

0x03 ready to achieve:

0x001

when generating a priority in the SDK, the receivers required to check for push:

Static checks to see if the corresponding component can be found, if no component is found (including no receiver at all, note that there is no component found, not "found component, just false"), the direct return priority is 0, otherwise the default check passes, The priority generation algorithm is generated according to the precedence level.

0x002

A case: initially configured as android:enabled= "false" in manifest, and then try to enable the component at some point in the future, so that it can receive broadcasts. From the above results, if the value is not dynamically modified, then the default is 0, the static check is not found this component, so that the broadcast can not be used properly. So, when enabled, execute: Dynamically change its value to 1, and then make a new round of static checks when Startwork is called, which is found to be passing, so you can generate a priority.

0x003

If you want to close an integrated Baidu push app, as long as its priority dropped to 0, you can find: if you dynamically set their value to 2, and then call Starwork for a new round of static checks, you will find that the priority to 0.

Static settings

Dynamic settings

Expected status

Static value

Components can be found

can receive broadcasts

No statement displayed

No

True

True

True

True

DEFAULT

True

True

True

True

ENABLED

True

True

True

True

DISABLED

False

True

False

False

True

No

True

True

True

True

DEFAULT

True

True

True

True

ENABLED

True

True

True

True

DISABLED

False

False

False

False

False

No

False

——

False

False

DEFAULT

False

——

False

False

ENABLED

True

False

True

True

DISABLED

False

——

False

False

Not registered

——

False

False

False

False

As can be obtained from the table above, regardless of the classification, as long as it is dynamically set to enabdled, the static check can be received, but also can receive broadcasts, but if it is dynamically set to DISABLED, there are several cases where the component is not detected statically. So you have to do a static check when calling Startwork (check to see if the component is found, not whether its activityinfo.enabled field's value is true or false).

0x04 Note: found in Tests

0x001

when the disabled/enabdled State of a component is dynamically modified, the result of this dynamic modification is persistent when the application exits or restarts.

0x002

If the machine does not unload, just reinstall, these disabled/enabdled will not be overwritten by the new installation.

Android static and dynamic set receiver's android:enabled value

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.