Broadcast publishing and receiving mechanism of uniapp and Android

Background: the app needs to listen to the broadcast of the third-party app to obtain application credentials and user credentials

Introduction:

Broadcast registration is mainly divided into static broadcast registration and dynamic broadcast registration. Since static broadcast registration needs to modify AndroidManifest.xml, static registration is not used on uniapp. I mainly refer to the broadcast mechanism of Android to realize the broadcast mechanism (dynamic broadcast) of uniapp's native writing method.

Dynamic registration broadcast: it follows the life cycle of the Activity. The broadcast receiver needs to be removed before the Activity ends.

Static registration broadcast: When the application is closed, if there is a broadcast, the program will also be automatically run by the system call.

1. Send a broadcast

Customize broadcast actions and pass parameters to broadcast receivers

android

private IntentFilter intentFilter;
private BootCompleteReceiver bootCompleteReceiver;
 
 
public class MainActivity18 extends AppCompatActivity {
    private IntentFilter intentFilter;
    private BootCompleteReceiver bootCompleteReceiver;
    
 
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main17);
        Button button33=findViewByI

Guess you like

Origin blog.csdn.net/weixin_51258044/article/details/126163228