Android starts built-in APK and dynamically sends and receives custom broadcast examples

Android starts built-in APK and dynamically sends and receives custom broadcast examples

In case of such a demand at work, you need to add a family number to the key, provide an interface, start the built-in APK, think and decide to change the framework again and again, and use the broadcast mechanism to realize it.

1、 Code dynamic self starting built-in apk

We all know that the Android system provides us with many service management classes. Packagemanager mainly manages application packages. Through it, we can obtain application information, build intent and start corresponding applications. In addition, Android has not yet provided some corresponding classes to manage relevant XML files. For example, you can obtain the information of androidmanifest.xml file through packageinfo; Packageiteminfo - the base class of all nodes in the androidmanifest.xml file, which provides basic information of these nodes, such as label, icon and meta data. But it does not use directly, but inherits from subclasses and calls corresponding methods. Applicationinfo inherits from packageiteinfo and is used to obtain the information of nodes in a specific program, such as common fields: flags field: * * flag_ System system application, flag_ EXTERNAL_ Storage indicates that the application is installed in the sdcard; Activityinfo also inherits from packageiteinfo, which is used to obtain information in the application or nodes. We can use it to obtain any properties we set, such as theme, launchmode, launchmode, etc. serviceinfo is similar to activityinfo, but it is used to obtain node information; The last resolveinfo is to obtain the information of the directory on its upper level based on the node, such as, and node information.

1. Introduction to packagemanager

Packagemanager is mainly used to manage application packages and obtain the relevant information of the application packages installed in the program. It is an abstract class, but we can obtain the packagemanager object through the getpackagemanager () method.

2. Code implementation

When the package name and mainactivity are unknown:

When the package name and mainactivity are known:

**2、 Dynamically send and receive broadcasts

1. Send custom broadcast**

2. Define broadcast receiver and process

3. Register broadcast receiver

4. Remember to release the broadcast after use, otherwise there will be a hidden danger of oom

This is the simplest built-in APK and broadcast sending method,

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>