Skip to content

Instantly share code, notes, and snippets.

@XavierTalpe
Last active December 17, 2015 12:49
Show Gist options
  • Select an option

  • Save XavierTalpe/5612793 to your computer and use it in GitHub Desktop.

Select an option

Save XavierTalpe/5612793 to your computer and use it in GitHub Desktop.
Intercepting broadcasts to other applications in Android.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<application>
<receiver android:name=".SmsReceivedBroadcastReceiver">
<!-- A high priority makes sure our BroadCastReceiver is called first. -->
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
</manifest>
public final class SmsReceivedBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive( Context aContext, Intent aIntent ) {
// Process event.
Toast.makeText( aContext, "Received SMS", Toast.LENGTH_LONG );
// Prevent others from receiving broadcast.
abortBroadcast();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment