exp_on_sdk

Broadcast

静态注册

  • 添加类继承, 用于处理广播消息

    1
    2
    3
    4
    public class staticBcr extends BroadcastReceiver{
        public void onReceive(Context context, Intent intent) {  
        }  
    }
  • 在AndroidManifest.xml 中添加

1
2
3
4
5
6
<receiver android:name="staticBcr">  
    <intent-filter>  
        <action  
            android:name="com.testBroadcastReceiver.Internal_2"/>  
    </intent-filter>  
</receiver>

动态注册

在函数中调用函数来注册

1
2
3
4
5
6
7
8
9
10
11
IntentFilter filter = new IntentFilter();//  
filter.addAction(Intent.ACTION_BATTERY_CHANGED);//系统电量检测信息  
filter.addAction(INTENAL_ACTION_3);//第三组自定义消息  

BroadcastReceiver dynamicBcr = new BroadcastReceiver(){
   public void onReceive(Context context, Intent intent) 
{
}
};
registerReceiver(dynamicBcr, filter);
registerReceiver(dynamicBcr, filter);

发送广播

Intent intent = new Intent(INTENAL_ACTION_3);  
intent.putExtra("Name", "hellogv");  
intent.putExtra("Blog", "http://blog.csdn.net/hellogv");  
intentsendBroadcast(intent);//传递过去

exp_on_sdk
https://leafflow.top/2016/04/12/other/exp-on-sdk-2016-04-12/
作者
vollen
发布于
2016年4月12日
许可协议