我想开发一个短信应用程序,这将发送多个短信在同一时间。我想给短信设置一个id。在短信发送报告中,我想得到这个id。因此,我将了解到已经发送了特定的消息。
我已经添加了广播接收器。我也收到了短信发送的报告。
我发了10条短信,我收到了8条短信报告。如何辨别哪两条消息未发送,以便重新发送?
发布于 2012-10-10 23:33:13
对于您发送的每条短信(或部分短信),您都需要提供一个PendingIntent。您在PendingIntent中放置了一个意图,无论发送成功与否,您都将收到该意图。在这种情况下,您可以使用extras添加额外的信息。因此,例如,当发送消息时,代码可能如下所示...
String receiverCodeForThisMessage = "STRING_CODE_FOR_MY_SMS_OUTCOME_RECEIVER";
int uniqueCodeForThisPartOfThisSMS = 100*numberSMSsentSoFar+PartNumberOfThisSMSpart;
Intent intent = new Intent(receiverCodeForThisMessage);
intent.putExtra("TagIdentifyIngPieceOfInformationOne", piece1);
intent.putExtra("TagIdentifyIngPieceOfInformationTwo", piece2);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, uniqueCodeForThisPartOfThisSMS, intent, 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("phonenumber", "Fred Bloggs", "Hello!", pendingIntent, null);但在此之前,您将注册一个接收器,它将获得结果和您设置的意图;从该意图中提取信息片段:
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
// Get information about this message
int piece1 = intent.getIntExtra("TagIdentifyIngPieceOfInformationOne", -1);
int piece2 = intent.getIntExtra("TagIdentifyIngPieceOfInformationTwo", -1);
if (getResultCode() == Activity.RESULT_OK) {
// success code
}
else {
// failure code
}
}, new IntentFilter(receiverCodeForThisMessage));https://stackoverflow.com/questions/12821943
复制相似问题