Broadcast Receivers

System wide events that happen on the device. Application can listen to messages for events, and use the intent filter to create act based on the message.

Type of broadcasts

Messages can be generated by the system, but also by applications.

System broadcasts

We can see the broadcast receivers based on each api for in the following folder:

C:\\Users\\iron\\AppData\\Local\\Android\\Sdk\\platforms\\android-26\\data\\broadcast_actions.txt

For example:

android.accounts.LOGIN_ACCOUNTS_CHANGED
android.accounts.action.ACCOUNT_REMOVED
android.app.action.ACTION_PASSWORD_CHANGED
android.app.action.ACTION_PASSWORD_EXPIRING
android.app.action.ACTION_PASSWORD_FAILED
android.app.action.ACTION_PASSWORD_SUCCEEDED
android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED
android.app.action.DEVICE_ADMIN_DISABLED
android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED
android.app.action.DEVICE_ADMIN_ENABLED
android.app.action.DEVICE_OWNER_CHANGED
android.app.action.INTERRUPTION_FILTER_CHANGED
android.app.action.LOCK_TASK_ENTERING
android.app.action.LOCK_TASK_EXITING
android.app.action.NEXT_ALARM_CLOCK_CHANGED
android.app.action.NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED
android.app.action.NOTIFICATION_POLICY_CHANGED
android.app.action.PROFILE_PROVISIONING_COMPLETE
android.app.action.SYSTEM_UPDATE_POLICY_CHANGED
android.appwidget.action.APPWIDGET_DELETED
android.appwidget.action.APPWIDGET_DISABLED
android.appwidget.action.APPWIDGET_ENABLED

Application broadcasts

Application can define their own broadcast, which can be used inside the app or transmit to a different app

Static vs Dynamic Broadcast

Static - A static entry in the Android Manifest file which listen to a receiver (Broadcast-receiver) or a intent filter.

Dynamic - Not in the manifest, only valid for the application life cycle (meaning when it runs or in the background, if it's closed the broadcast is not registered) and is located in a class method. It will use the registerReceiver function to create new intent.

For example the following application

{% file src="../../.gitbook/assets/DynamicBR.apk" %} DynamicBR.apk {% endfile %}

We can create new intent, by creating a new app and calling the broadcast receiver

        val intent = Intent("edu.ksu.cs.action.EMAIL")
        intent.putExtra("email","iron@ironattacker.com")
        intent.putExtra("text","exploitng dynamically registered Broadcast reciver")
        sendBroadcast(intent)