是否有可能重新发送SMS_RECEIVED广播?(Is it possible to resend

2019-11-01 02:14发布

我要重新发送收到SMS_RECEIVED广播。 我在这里找到例子: 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);
                }

            }
        }
    }
};

但是这个代码崩溃com.android.mms(我看 “I / ActivityManager(71):流程com.android.mms(PID 904)已经死亡。” 在logcat中)与此:

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)

如何解决呢?

Answer 1:

如果要使用相同的数据(相同的接收SMS)这将是更好地重复使用相同的目的,并不托盘建立你自己的。 只需使用intent.putExtras(捆绑演员); 您可以替换 “update.putExtra( ”PDU的“,新的对象[] {}的PDU);” 用 “update.putExtra(pudsBundle)”。 试试吧,让我知道,如果它的作品,我没有时间重现。



文章来源: Is it possible to resend SMS_RECEIVED broadcast?