1、动态注册广播
/**
* 注册广播:定义当前广播唯一的action
* <p>
* 一般在onCreate中调用
*/
private void registerReceiver() {
IntentFilter filter = new IntentFilter("android.intent.action.yourAction");
registerReceiver(myReceiver, filter);
}
/**
* 注销广播:在onDestroy中调用
*/
private void unregisterReceiver() {
unregisterReceiver(myReceiver);
}
2、发送广播
Intent intent = new Intent("android.intent.action.youraction");
intent.putExtra("payload", entity.getContentByteArray());
sendBroadcast(intent);