简体   繁体   English

是否可以重新发送SMS_RECEIVED广播?

[英]Is it possible to resend SMS_RECEIVED broadcast?

I want to resend received SMS_RECEIVED broadcast. 我想重新发送收到的SMS_RECEIVED广播。 I've find example here: http://blog.dev001.net/post/14085892020/android-generate-incoming-sms-from-within-your-app and make it by analogy: 我在这里找到了示例: http : //blog.dev001.net/post/14085892020/android-generate-incoming-sms-from-within-your-app ,并通过类比将其制作为:

boolean received=false;

private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
            if(!received) {

                received=true;

                Bundle pudsBundle = intent.getExtras();
                Object[] pdus = (Object[]) pudsBundle.get("pdus");
                SmsMessage messages =SmsMessage.createFromPdu((byte[]) pdus[0]);

                abortBroadcast();

                if(/*my condition here*/) {
                    Intent update = new Intent();
                    update.setClassName( "com.android.mms", "com.android.mms.transaction.SmsReceiverService");
                    update.setAction("android.provider.Telephony.SMS_RECEIVED");
                    update.putExtra( "pdus" , new Object[] { pdus });
                    startService(update);
                }

            }
        }
    }
};

But this code crash com.android.mms (I see "I/ActivityManager(71): Process com.android.mms (pid 904) has died." in LogCat) with this: 但是此代码使com.android.mms崩溃(我在LogCat中看到“ I / ActivityManager(71):进程com.android.mms(pid 904)已死。”):

threadid=8: thread exiting with uncaught exception (group=0x4001d800)
FATAL EXCEPTION: SmsReceiverService
java.lang.ClassCastException: [Ljava.lang.Object;
    at android.provider.Telephony$Sms$Intents.getMessagesFromIntent(Telephony.java:617)
    at com.android.mms.transaction.SmsReceiverService.handleSmsReceived(SmsReceiverService.java:299)
    at com.android.mms.transaction.SmsReceiverService.access$100(SmsReceiverService.java:67)
    at com.android.mms.transaction.SmsReceiverService$ServiceHandler.handleMessage(SmsReceiverService.java:172)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.os.HandlerThread.run(HandlerThread.java:60)

How to fix it? 如何解决?

If you want to use the same data( same received sms) it would be better to reuse the same intent and don't tray to build your own. 如果您想使用相同的数据(接收到的短信相同),则最好重用相同的意图,而不要自己构建。 just use intent.putExtras(Bundle extras); 只需使用intent.putExtras(Bundle extras); Can you replace "update.putExtra( "pdus" , new Object[] { pdus });" 您可以替换“ update.putExtra(” pdus“,new Object [] {pdus});” with "update.putExtra(pudsBundle)". 与“ update.putExtra(pudsBundle)”。 Try it and let me know if it works, i haven't time to reproduce. 试试看,让我知道它是否有效,我还没有时间复制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM