如何获得小区广播消息? [英] How to get Cell Broadcast message?

查看:132
本文介绍了如何获得小区广播消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让小区广播消息就像短信的文字,但它does'not工作:

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?

推荐答案

我也花了一些时间对这一问题的调查。它似乎没有公共API来做到这一点。但我可以从我的逆向工程研究分享了一些成果......

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...

我的三星Galaxy S能够接收小区信息,所以我反编译的短信应用程序,并调查了code。它具有以下的BroadcastReceiver 在其清单文件:

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>

注意 android.provider.Telephony.CB_RECEIVED 意图过滤器。我没有找到任何文件有关,但是从它的名字,我以为这就是我需要赶上现在唯一的广播。

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.

然后,我通过搜索反编译的apk的code,发现它使用 android.provider.Telephony.Sms.Intents-&GT; getCbMessagesFromIntent()接口访问取得的CB消息,它返回 CbMessage 类的实例。这个接口是过时的甚至是简单的短信,所以我认为 CbMessage 的PDU 工作作为 SmsMessage 一样。最后,我找到了<一href="http://www.java2s.com/Open-Source/Android/android-core/platform-frameworks-base/android/telephony/SmsCbMessage.java.htm">source 。对 SmsCbMessage 类,它是由API类似于 SmsMessage pretty的这取决于5-6内部的Andr​​oid java文件,所以为了简单起见,我刚刚从同一网站抓住他们,包括他们到我的项目。 该的BroadcastReceiver 是一样的你,除了类 SmsMessage 替换 SmsCbMessage

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();
        }                         
    }
}

安装我的申请,我SGS手机接收器上面,并使接收手机短信应用的CB消息后,我的应用程序能够显示出与标准的短信应用程序接收他们敬酒并行CB消息。

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:

  • 如何启用CB消息的/禁止/ configure_channels我 应用?短信应用程序使用 getCbSettings() / setCbSettings()功能, 但我没有找到他们。所以暂时我用其他的应用程序为。
  • 如何 中止CB消息广播,让其他应用程序不接受呢?它 似乎 abortBroadcast()不在这里工作了,因为广播 信息不排序( isOrderedBroadcast()返回)。
  • 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).

这篇关于如何获得小区广播消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆