发送有序广播案例

包com.edu.bzu.broadcast;

导入android.content.BroadcastReceiver;
导入android.content.Context;
import android.content.Intent;
导入android.util.Log;

/ **
 *由dpl在2017/6/4 0004创建。
 * /

public class MyBroadcastReceiverTwo extends BroadcastReceiver {
    @覆盖
    public void onReceive(Context context,Intent intent){
        Log.i( “MyBroadcastReceiverTwo”, “自定义的广播接收者两个,接收到了广播”);
    }
}

1. 程序启动后,单击“发送有序广播”按钮,发出一条广播事件,此时观察logcat的窗口下的提示信息,输出什么?

2.案例所需图片:





3.运行效果图:


<img src="<font><font class=" "="">


3.文件目录:



4.布局activity_main:
<?xml version =“1.0”encoding =“utf-8”?>
<RelativeLayout xmlns:android =“http://schemas.android.com/apk/res/android”
    的xmlns:工具= “http://schemas.android.com/tools”
    机器人:ID = “@ + ID / activity_main”
    机器人:layout_width = “match_parent”
    机器人:layout_height = “match_parent”
    机器人:背景= “@绘制/ stitch_one”
    工具:上下文= “com.edu.bzu.broadcast.MainActivity”>
  <按钮
      机器人:layout_width = “WRAP_CONTENT”
      机器人:layout_height = “WRAP_CONTENT”
      机器人:layout_centerHorizo​​ntal = “真”
      机器人:layout_marginTop = “80dp”
      安卓的onClick =“发送”
      机器人:文字= “发送有序广播”
      机器人:paddingLeft = “5DP”
      机器人:paddingRight = “5DP”
      机器人:背景= “#fbfbff”
      机器人:TEXTSIZE = “20SP”/>

</ RelativeLayout的>

5.AndroidManifest:
<?xml version =“1.0”encoding =“utf-8”?>
<manifest xmlns:android =“http://schemas.android.com/apk/res/android”
    包= “com.edu.bzu.broadcast”>

    <应用
        机器人:allowBackup = “真”
        机器人:图标= “@ mip映射/ ic_launcher”
        机器人:标签= “@字符串/ APP_NAME”
        机器人:supportsRtl = “真”
        机器人:主题= “@风格/ AppTheme”>
        <activity android:name =“。MainActivity”>
            <意图滤波器>
                <action android:name =“android.intent.action.MAIN”/>

                <category android:name =“android.intent.category.LAUNCHER”/>
            </意图滤波器>
        </活动>
        <receiver android:name =“。MyBroadcastReceiverOne”>
            <intent-filter android:priority =“1000”>
                <action android:name =“Intercept_Stitch”/>
            </意图滤波器>
        </接收机>
        <receiver android:name =“。MyBroadcastReceiverTwo”>
            <intent-filter android:priority =“200”>
                <action android:name =“Intercept_Stitch”/>
            </意图滤波器>
        </接收机>
        <receiver android:name =“。MyBroadcastReceiverThree”>
            <intent-filter android:priority =“600”>
                <action android:name =“Intercept_Stitch”/>
            </意图滤波器>
        </接收机>
    </应用>

</清单>


6.MainActivity:
包com.edu.bzu.broadcast;

import android.content.Intent;
导入android.support.v7.app.AppCompatActivity;
导入android.os.Bundle;
导入android.view.View;

公共课MainActivity扩展AppCompatActivity {

    @覆盖
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
    }
    public void send(查看视图){
        Intent intent = new Intent();
        intent.setAction( “Intercept_Stitch”);
        sendOrderedBroadcast(意向,NULL);
    }
}
7.MyBroadcastReceiverOne,MyBroadcastReceiverOne,MyBroadcastReceiverOne类:

包com.edu.bzu.broadcast;

导入android.content.BroadcastReceiver;
导入android.content.Context;
import android.content.Intent;
导入android.util.Log;

/ **
 *由dpl在2017/6/4 0004创建。
 * /

public class MyBroadcastReceiverOne extends BroadcastReceiver {
    @覆盖
    public void onReceive(Context context,Intent intent){
        Log.i( “MyBroadcastReceiverOne”, “自定义的广播接收者的一个,接收到了广播”);
    }
}
包com.edu.bzu.broadcast;

导入android.content.BroadcastReceiver;
导入android.content.Context;
import android.content.Intent;
导入android.util.Log;

/ **
 *由dpl在2017/6/4 0004创建。
 * /

public class MyBroadcastReceiverTwo extends BroadcastReceiver {
    @覆盖
    public void onReceive(Context context,Intent intent){
        Log.i( “MyBroadcastReceiverTwo”, “自定义的广播接收者两个,接收到了广播”);
    }
}
包com.edu.bzu.broadcast;

导入android.content.BroadcastReceiver;
导入android.content.Context;
import android.content.Intent;
导入android.util.Log;

/ **
 *由dpl在2017/6/4 0004创建。
 * /

public class MyBroadcastReceiverThree extends BroadcastReceiver {
    @覆盖
    public void onReceive(Context context,Intent intent){
        Log.i( “MyBroadcastReceiverThree”, “自定义的广播接收者三,接收到了广播”);
    }
}



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值