zoukankan      html  css  js  c++  java
  • android中的广播接收实现总结

    1 首先根据广播应用内接收和应用外接收,分两个类进行管理
    [1]  LocalBroadcastManager,应用内广播管理类
    [2]  BroadcastManager  广播管理类(部分应用内,应用外)

    2 广播接收类实现的两种方式
    [1] 代码生成类,并注册
    public class MessageReceiver extends BroadcastReceiver {

            @Override
            public void onReceive(Context context, Intent intent) {
                 
                }
         
         
        }

     //代码注册广播接收类
    public void registerMessageReceiver() {
            mMessageReceiver = new MessageReceiver();
            IntentFilter filter = new IntentFilter();
            filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
            filter.addAction(MESSAGE_RECEIVED_ACTION);
            registerReceiver(mMessageReceiver, filter);
        }

    [2] 在AndroidManifest.xml 文件中配置广播接收类
    <receiver
                android:name="com.example.jpushdemo.MyReceiver"
                android:enabled="true">
                <intent-filter>
                    <action android:name="cn.jpush.android.intent.REGISTRATION" /> <!--Required  用

    户注册SDK的intent-->
                    <action android:name="cn.jpush.android.intent.UNREGISTRATION" />  
                    <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /> <!--Required 

     用户接收SDK消息的intent-->
                    <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /> <!--

    Required  用户接收SDK通知栏信息的intent-->
                    <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /> <!--

    Required  用户打开自定义通知栏的intent-->
                    <action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK" /> 

    <!--Optional 用户接受Rich Push Javascript 回调函数的intent-->
                    <category android:name="com.example.jpushtest" />
                </intent-filter>
            </receiver>

    3 消息发送的两种方式
        Normal broadcast,通过Context.sendBroadcast 发送,接口器不按照顺序,异步处理
        Ordered broadcasts ,通过Context.sendOrderedBroadcast发送,由于每个接收器依次执行时,它可以

    传播的结果到下一个接收器,或者它可以完全中止该广播,以便它不会被传递给其他接收者。排列顺序为接

    收器的优先级

  • 相关阅读:
    将查询语句创建新表
    java冒泡排序
    java三元运算符
    java中的>>>和>>>=
    i++和++i
    设计4个线程,其中两个线程每次对j增加1,另外两个线程对j每次减少1。
    System.out.println与System.err.println的区别
    try-catch-finally
    Java常见异常类
    Vue.js环境配置
  • 原文地址:https://www.cnblogs.com/macroxu-1982/p/3648516.html
Copyright © 2011-2022 走看看