广播接收者---发送有序广播
2017-06-05 08:54
375 查看
广播接收者----发送有序广播
1.功能描述:实现拦截一条有序广播。2.技术要点:通过sendOrderedBroadcast()方法实现发送一条有序广播。
(1).用户交互界面的设计与实现
(2).界面交互代码的设计与实现
(3).创建3个广播接收者
MyReceiverOne.java
MyReceiverTwo.java
MyReceiverThree.java
3.实现步骤:设置广播接收者的优先级
4.
.
5.具体实现代码:
MainActivity
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void send(View view){ Intent intent=new Intent(); intent.setAction("intercept_stitch"); sendBroadcast(intent,null); } }6.MyReceiverOne.java
public class MyReceiverOne extends BroadcastReceiver { public MyReceiverOne() { } @Override public void onReceive(Context context, Intent intent) { Log.i("MyReceiverOne","自定义的广播接收者one,接收到了广播事件"); } }7.MyReceiverTwo.jsva
public class MyReceiverTwo extends BroadcastReceiver { public MyReceiverTwo() { } @Override public void onReceive(Context context, Intent intent) { Log.i("MyReceiverTwo","自定义广播接收者Two,已接受到了广播事件"); } }8.MyReceiverThree.java
public class MyReceiverThree extends BroadcastReceiver { public MyReceiverThree() { } @Override public void onReceive(Context context, Intent intent) { Log.i("MyreceiverThree","自定义广播接收者Three,已接收到了广播事件"); } }9.清单文件:AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.edu.bzu.myapplication"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".MyReceiverOne" > <intent-filter android:priority="1000"> <action android:name="intercept_stitch"></action> </intent-filter> </receiver> <receiver android:name="cn.edu.bzu.myapplication.MyReceiverTwo" > <intent-filter android:priority="200"> <action android:name="intercept_stitch" ></action> </intent-filter> </receiver> <receiver android:name="cn.edu.bzu.myapplication.MyReceiverThree" > <intent-filter android:priority="600"> <action android:name="intercept_stitch" ></action> </intent-filter> </receiver> </application> </manifest>10.运行界面:
相关文章推荐
- Android--广播接收者(发送有序广播)
- 安卓BroadcastReceiver组件使用系列2:给多个广播接收者发送广播和有序广播的使用
- Android 广播接收者练习-发送有序广播
- 广播接收者之发送有序广播
- 广播接收者-发送有序广播
- Android-广播接收者:发送有序广播
- 发送一条有序广播
- Android短信的发送和广播接收者实现短信的监听
- 发送与接收广播(普通,有序)
- 发送有序广播
- 发送有序广播
- 用安卓发送有序广播
- android-BroadcastReceiver 发送有序广播
- Android短信的发送和广播接收者实现短信的监听
- android,自定义广播,最终广播接收者,防止拦截广播,有序广播,无序广播
- Android短信的发送和广播接收者实现短信的监听
- 发送有序广播
- 发送有序广播
- 发送有序广播
- 发送有序广播案例