6

I try to get text of Cell Broadcast message just like sms, but it does'not work:

public class SMSReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null; String str = ""; if (bundle != null) { // ---retrieve the SMS message received--- Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int i = 0; i < msgs.length; i++) { msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); str =msgs[i].getOriginatingAddress(); str += " :"; str += msgs[i].getMessageBody().toString(); 

Do you know any way to get it?

2
  • 1
    What do you mean by cell broadcast message, like a push notification, or ...? Commented Aug 25, 2011 at 3:35
  • @Jakar - Cell Broadcast Commented Sep 20, 2011 at 16:49

1 Answer 1

9

I also spent some time on investigation of this question. And it seems that there is no public API to do that. But I can share some results from my reverse engineering research...

My Samsung Galaxy S is able to receive CB messages, so I decompiled SMS app and looked into the code. It has the following BroadcastReceiver in its manifest file:

 <receiver android:name=".transaction.PrivilegedSmsReceiver"> ... <intent-filter> <action android:name="android.provider.Telephony.CB_RECEIVED" /> </intent-filter> <intent-filter> <action android:name="android.provider.Telephony.CB_SETTINGS_AVAILABLE" /> </intent-filter> <intent-filter> <action android:name="android.provider.Telephony.SET_CB_ERR_RECEIVED" /> </intent-filter> <intent-filter> <action android:name="android.provider.Telephony.GET_CB_ERR_RECEIVED" /> </intent-filter> </receiver> 

Note the android.provider.Telephony.CB_RECEIVED intent-filter. I did not find any documentation about it, but from its name I assumed that it's the only broadcast that I need to catch for now.

Then I searched through the code of decompiled apk and found that it uses android.provider.Telephony.Sms.Intents->getCbMessagesFromIntent() interface to access retrieve CB messages, which returns CbMessage class instance. This interface is outdated even for simple SMS messages, so I assumed that CbMessage should work with pdus as SmsMessage does. Finally I found the source of SmsCbMessage class which is pretty similar to SmsMessage by API. It depends on 5-6 internal Android java files, so for simplicity I just grab them from the same site and included them into my project. The broadcastReceiver is the same as yours except the class SmsMessage is replaced by SmsCbMessage:

public class CbReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //---get the CB message passed in--- Bundle bundle = intent.getExtras(); SmsCbMessage[] msgs = null; String str = ""; if (bundle != null) { //---retrieve the SMS message received--- Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsCbMessage[pdus.length]; for (int i=0; i<msgs.length; i++) { msgs[i] = SmsCbMessage.createFromPdu((byte[])pdus[i]); str += "CB lang " + msgs[i].getLanguageCode(); str += " :"; str += msgs[i].getMessageBody().toString(); str += "\n"; } //---display the new CB message--- abortBroadcast(); Toast.makeText(context, str, Toast.LENGTH_SHORT).show(); } } } 

After installing my application into my SGS phone with the receiver above, and enabling receiving CB messages in phone SMS application, my app was able to show CB messages in toast in parallel with receiving them by standard SMS application.

The issues are still needed to be resolved:

  • How to enable/disable/configure_channels of CB messages in my application? SMS app uses getCbSettings()/setCbSettings() functions, but I did not find them. So temporarily I used other app for that.
  • How to abort CB message broadcast, so other apps do not receive them? It seems abortBroadcast() does not work here, because the broadcast message is not ordered (isOrderedBroadcast() returns false).
Sign up to request clarification or add additional context in comments.

14 Comments

Thank you, but unfortunately it does not work in my case. Do you have any permissions in manifest?
No special permissions, just the android.permission.RECEIVE_SMS. Also I had to enable CB receiving in standard SMS application.
HTC Desire have no CB settings in standart SMS application. It can be enabled only from common phone settings. So... looks like it's just for Samsung Galaxy S. Thank you, anyway.
@GrAnd Are you succeeded using abortBroadCast
did you ever get the aborting to work? we are trying to create a new "inbox" app, that will receive the messages instead of going to the SMS inbox
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.