62.9 Registering the Broadcast Receiver
The project needs to publicize the presence of the broadcast receiver and must include an intent filter to specify the broadcast intents in which the receiver is interested. When the BroadcastReceiver class was created in the previous section, Android Studio automatically added a <receiver> element to the manifest file. All that remains, therefore, is to add code within the MainActivity.kt file to create an intent filter and to register the receiver:
package com.ebookfrenzy.sendbroadcast
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.content.Intent
import android.view.View
import android.content.IntentFilter
import android.content.BroadcastReceiver
class MainActivity : AppCompatActivity() {
var receiver: BroadcastReceiver? = null
override fun onCreate(savedInstanceState: Bundle?)...