sendMultipartTextMessage 中Delivered List<Pendingintent> 广播 Intent参数传递不刷新问题

本文分享了在Android开发中使用sendMultipartTextMessage发送短信时遇到的广播参数不刷新问题,通过更改PendingIntent的Action参数,成功解决了短信发送状态监听的困扰。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

初入android的坑,有什么错误 和 问题,大家指出来,多谢了

这段时间由于私人需求,要做个短信多发软件 就想起用AS开发 结果在 sendMultipartTextMessage时遇到了

困顿我好几天的问题,在百度上查找 Pendingintent 参数 也是没什么作用(sendMultipartTextMessage 的使

用也是在网上看的)

跑题了。。。

先说说是什么问题吧:sendMultipartTextMessage(String,sc,ArrayList<String>,ArrayList<Pendingintent> sents,ArrayList<Pendingintent> devs)

这个函数 中的devs广播 参数 不刷新 一直是第一个的参数。嗯 。没遇到此问题的大佬 萌新可以撤了 哈哈

后来我一直苦苦思考是不是 Pendingintent.getBroadcast  的参数传错了  一直到第三天 我尝试 将 Intent(Action)

 和 IntentFliter(Action)中的Action改成变化值 这个问题才被解决 

我承认我思维混乱  胡说八道  所以  下面用代码实例来说明吧

 int times = 0;

private PendingIntent RegisterReceiver_SendSms(int index, final String Id) {//创建一个监听发送结果的广播
    String Action = getString(R.string.Send_Sms_Action);//Action=“SEND_SMS_ACTION”
    Intent paramIntent = new Intent(Action);

    Log.i(TAG, "RegisterReceiver_SendSms压入参数: Id: " + Id + " Index: " + index);
    paramIntent.putExtra("Id", Id);
    paramIntent.putExtra("Index", index);

    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, times++, paramIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    Log.i(TAG, "RegisterReceiver_SendSms Times:" + times);
    MyService.this.registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle bundle = intent.getExtras();
            String Id = bundle.getString("Id");
            int index = bundle.getInt("Index");
            context.unregisterReceiver(this);
        }
    }, new IntentFilter(Action));
    return pendingIntent;
}

private PendingIntent RegisterReceiver_Delivered(int index, final String Id) {//创建一个监听是否送达的广播
    times++;
    String Action = getString(R.string.Delivered_Sms_Action);//Action=“DELIVERED_SMS_ACTION”
    Intent sendIntent = new Intent(Action+times);//修改之前这里只有个Action
    Log.i(TAG, "RegisterReceiver_Delivered压入参数: Id: " + Id + " Index: " + index);
    sendIntent.putExtra("Id", Id);
    sendIntent.putExtra("Index", index);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, times, sendIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    Log.i(TAG, "RegisterReceiver_SendSms Times:" + times);
    MyService.this.registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle bundle = intent.getExtras();
            String Id = bundle.getString("Id");
            int index = bundle.getInt("Index");
            Log.i(TAG, "index :" + index);
            context.unregisterReceiver(this);
        }
    }, new IntentFilter(Action+times));//修改之前这里只有个Action
    return pendingIntent;
}

这个是发送短信函数里面的片段:

ArrayList<String> dvideSms = smsManager.divideMessage(Sms);
for (int i = 0; i < dvideSms.size(); ++i) {
    SentInts.add(RegisterReceiver_SendSms(CurrIndex, Id));
    Delivereds.add(RegisterReceiver_Delivered(CurrIndex, Id));
}
smsManager.sendMultipartTextMessage(PhoneNumber, null, dvideSms, SentInts, Delivereds);//发送

CurrIndex 是 自增变量范围:[0,2],自增条件为每重新执行这个发送短信函数

 假如 短信全部发送并被接收了 那正确输出的日志
应该是 index : 0       而实际上未修改之前是  index : 0
             index : 1                                                 index : 0
             index : 2                                                 index : 0

我也不知道是什么原因 也不知道会有什么问题  但确确实实解决了我当前的问题

 

在导出word时通过xml转world,帮我把下面富文本的标签替换为xml转word的标签,文本是存储在一个String字符串remark中,通过java代码进行替换<p>欧盟ICS2已经正式开始申报</p> <p>1)请客户务必自行检查EORI是否有效 EORI number validation (europa.eu)https://ec.europa.eu/taxation_customs/dds2/eos/eori_validation.jsp?Lang=en</p> <p>2)对于要更改EORI NO的提单,将收取改单费,未及时更改影响母船申报ICS2的提单,欧盟将产生“DO NOT LOAD”提示,导致无法在中转港装船的情况,请务必注意!</p> <p>3)对于到欧盟和经欧盟货物需要客户提供如下<span style="background-color: #fbeeb8;"> (要打乱顺序)</span>House Bill(s) included in the shipment: Y or NGoods delivered in EU:: Y or NBuyer and seller information equal to shipper and consignee: Y or NEORI of the supplementary declarant(下一申报方/补充申报方EORI No):NYY/NNY/NNN 无需提供EORI NO,船公司根据SI 内容发送欧盟海关其他情况YNY/YNN/YYN/YYY/NYN 需要提供准确的(申报方)EORI NO ,或者请自行登陆船公司网站https://mymsc.msccargo.cn/mymsc/申报ICS2 ,截止时间同SI CUT OFF 时间</p> <p>4)上述EORI涉及的国家和地区如下,仅供参考,请及时关注欧盟成员国的变化。</p> <table style="border-collapse: collapse; width: 210.03pt;" border="0" width="280" cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 19.50pt;"> <td style="height: 19.50pt; width: 54.00pt;" width="72" height="26">US</td> <td style="width: 156.00pt;" width="208">EIN+011705000</td> </tr> <tr style="height: 19.50pt;"> <td style="height: 19.50pt;" height="26">US</td> <td>EIN+261482306</td> </tr> </tbody> </table>
最新发布
06-12
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值