Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 如何获取Cell Broadcast消息?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_801_1@我尝试像短信一样得到Cell Broadcast消息的文本,但它不起作用:
public class SMSReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context,Intent intent) {
    Bundle bundle = intent.getExtras();
    Sms@R_616_8798@ge[] msgs = null;
    String str = "";
    if (bundle != null) {
        // ---retrieve the SMS @R_616_8798@ge received---
        Object[] pdus = (Object[]) bundle.get("pdus");
        msgs = new Sms@R_616_8798@ge[pdus.length];
        for (int i = 0; i < msgs.length; i++) {
            msgs[i] = Sms@R_616_8798@ge.createFromPdu((byte[]) pdus[i]);
            str =msgs[i].getOriginaTingAddress();
            str += " :";
            str += msgs[i].get@R_616_8798@geBody().toString();

你知道怎么办吗?

解决方法

我也花了一些时间研究这个问题.似乎没有公共API可以做到这一点.但我可以从逆向工程研究中分享一些结果……

我的三星Galaxy S能够接收CB消息,因此我反编译了SMS应用程序并查看了代码.它的清单文件中有以下BroadcastReceiver:

<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 intent-filter.我没有找到任何关于它的文档,但从它的名字我认为它是我现在需要捕获的唯一广播.

然后我搜索了反编译的apk代码,发现它使用android.provider.Telephony.Sms.Intents-> getCb@R_616_8798@gesFromIntent()接口来访问检索CB消息,返回Cb@R_616_8798@ge类实例.即使对于简单的SMS消息,此接口也已过时,因此我假设Cb@R_616_8798@ge应该与Sms@R_616_8798@ge一样使用pdus.最后我找到了source of SmsCbMessage类,它与API的Sms@R_616_8798@ge非常相似.这取决于5-6个内部Android java文件,所以为了简单起见,我只是从同一个站点获取它们并将它们包含在我的项目中.@H_675_17@broadcastReceiver与您的相同,只是Sms@R_616_8798@ge类替换为SmsMb@R_616_8798@ge:

public class CbReceiver extends BroadcastReceiver {

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

在将我的应用程序安装到带有上述接收器的SGS手机中,并在手机短信应用程序中启用接收CB消息之后,我的应用程序能够在通过标准SMS应用程序接收它们的同时在烤面包中显示CB消息.

这些问题仍有待解决

>如何在我的中启用/禁用/配置CB消息的信道应用? SMS应用程序使用getCbSetTings()/ setCbSetTings()函数,但我没找到他们.所以我暂时使用其他应用程序.>怎么样中止CB消息广播,以便其他应用程序不接收它们?它似乎abortBroadcast()在这里不起作用,因为广播消息未排序(isorderedBroadcast()返回falsE).

大佬总结

以上是大佬教程为你收集整理的android – 如何获取Cell Broadcast消息?全部内容,希望文章能够帮你解决android – 如何获取Cell Broadcast消息?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。