zoukankan      html  css  js  c++  java
  • 广播

    一个发布广播的类

     public void buttonBroadcaseStatic(View view){
            Intent intent = new Intent();
            //创建一个广播的名字
            intent.setAction("SB");
            sendBroadcast(intent);
           

    一个接受广播的类

    package com.example.zhuopeng.demo1;
    
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.widget.Toast;
    
    public class BroadcaseReceiver extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO: This method is called when the BroadcastReceiver is receiving
            // an Intent broadcast.
    //        throw new UnsupportedOperationException("Not yet implemented");
            Toast.makeText(context,"static BroadcaseReceiver is here ",Toast.LENGTH_SHORT).show();
            //截断广播
            //abortBroadcast();
        }
    }

    注册

    <receiver
                android:name=".BroadcaseReceiver"
                android:enabled="true"
                android:exported="true">
                <intent-filter android:priority="100"> <!-- 设置优先级,高优先级有权利截断广播 -->
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
                    <action android:name="SB" />
                </intent-filter>
            </receiver>

  • 相关阅读:
    LeetCode 48 Anagrams
    大数据实时处理:百分点实时计算架构和算法
    Kafka操作
    Kafka
    批量扫描互联网无线路由设备telnet,并获取WIFI密码
    WMI
    openvas
    原始套接字
    Zabbix
    MySQL exist
  • 原文地址:https://www.cnblogs.com/da-peng/p/8439617.html
Copyright © 2011-2022 走看看