55.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.java file to create an intent filter and to register the receiver:
package com.ebookfrenzy.sendbroadcast;
.
.
import android.content.BroadcastReceiver;
import android.content.IntentFilter;
.
.
public class MainActivity extends AppCompatActivity {
BroadcastReceiver receiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...