gpt4 book ai didi

带有 pendingIntents 的 Android SendMultipartTextMessage,所有部分的额外值都相同

转载 作者:行者123 更新时间:2023-11-29 15:50:37 33 4
gpt4 key购买 nike

我正在使用 Xamarin Studio 和 SMS.Telephony.SmsManager Android 库通过 Android 成功发送多部分(串联)消息。

要发送消息,我正在执行以下操作:

var longMessage = "This is a cØncatenated message sent to you through an android.   This should appear as a single message.  Hopefully it's as easy as that.  It even has a function to break the message up. It probably took me longer to install Xamarin then it did to write the code and send the actual message";
var smsMgr = Android.Telephony.SmsManager.Default;
System.Collections.Generic.IList<string> parts = smsMgr.DivideMessage(longMessage);
IList<PendingIntent> pendingIntents = new List<PendingIntent>(parts.Count);
for (int i = 0; i < parts.Count; i++)
{
var intent = new Intent(DeliveryIntentAction);
intent.PutExtra("MessagePartText", parts[i]);
intent.PutExtra("MessagePartId", i.ToString());
PendingIntent pi = PendingIntent.GetBroadcast(this, 0, intent, 0);
pendingIntents.Add(pi);
}

smsMgr.SendMultipartTextMessage("17057178131",null, parts, pendingIntents, null);

然后我有一个接收未决 Intent 的接收器,如下所示:

[BroadcastReceiver(Enabled = true)] //(Exported = true, Permission = "//receiver/@android:android.permission.SEND_SMS")]
[IntentFilter(new[] { DeliveryIntentAction }, Priority = int.MaxValue)]
public class SMSSentReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
if (intent.GetStringExtra ("MessagePartId") != null)
lbl.Text += " Sent Response " + intent.GetStringExtra ("MessagePartId") + System.Environment.NewLine;
...

但是,每次调用 OnRecieve 时,intent.GetStringExtra("MessagePartId") 的值为“0”并且 MessagePartText 是第一部分,而不是属于发送的消息部分的部分编号/文本。

谁能看出为什么会这样?

谢谢

最佳答案

使用 PendingIntent pi = PendingIntent.GetBroadcast(this, 0, intent, 0);尝试覆盖现有的 pendingIntent。

要创建一个新的 Intent 并让它等待,我必须更改 GetBroadcast 的 requestCode 参数。

PendingIntent pi = PendingIntent.GetBroadcast(this, i, intent, 0);

谢谢

关于带有 pendingIntents 的 Android SendMultipartTextMessage,所有部分的额外值都相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30224630/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com