I have a main application module "app1" and a second module "app2" that starts as "process:SecondActivity". I need to send a message from SecondActivity using a broadcast receiver, but the message does not come in onRecive. Broadcast receiver is in module "tools", Modules "app1" and "app2" dependent on the module "tools".
My broadcast receiver
class ExportReceiver : BroadcastReceiver() {
companion object {
const val ACTION_EXPORT = "ACTION_EXPORT"
@JvmStatic
fun getIntentFilters() = IntentFilter(ACTION_EXPORT)
}
@FunctionalInterface
interface OnExport {
fun onExport(uri: Uri)
}
private var mExport : OnExport? = null
override fun onReceive(context: Context?, intent: Intent?) {
intent?.let {
if (it.action == ACTION_EXPORT) {
it.data?.let { uri ->
mExport?.onExport(uri)
}
}
}
}
fun setExport(export: OnExport) {
mExport = export
}
}
Register receiver to "app1"
mExportReceiver = new ExportReceiver();
mExportReceiver.setExport(uri -> {});
mContext.registerReceiver(mExportReceiver, ExportReceiver.getIntentFilters());
Send broadcast to "app2"
override fun onExportFile(fileUri: Uri?) {
fileUri?.let {
sendBroadcast(Intent(ExportReceiver.ACTION_EXPORT).apply {
data = fileUri
})
}
}