5
0
mirror of https://github.com/cwinfo/envayasms.git synced 2025-03-15 06:52:31 +00:00
envayasms/src/org/envaya/kalsms/OutgoingMessage.java

110 lines
2.4 KiB
Java
Raw Normal View History

2011-09-13 14:55:26 -07:00
package org.envaya.kalsms;
2011-09-15 18:34:06 -07:00
import org.envaya.kalsms.receiver.OutgoingMessageRetry;
import org.envaya.kalsms.receiver.MessageStatusNotifier;
2011-09-13 14:55:26 -07:00
import android.app.PendingIntent;
import android.content.Intent;
import android.net.Uri;
import android.telephony.SmsManager;
public class OutgoingMessage extends QueuedMessage {
private String serverId;
private String message;
private String from;
private String to;
private String localId;
private static int nextLocalId = 1;
public OutgoingMessage(App app)
{
super(app);
this.localId = "_o" + getNextLocalId();
}
static synchronized int getNextLocalId()
{
return nextLocalId++;
}
2011-09-17 18:38:16 -07:00
public Uri getUri()
2011-09-13 14:55:26 -07:00
{
2011-09-17 18:38:16 -07:00
return Uri.withAppendedPath(App.OUTGOING_URI, ((serverId == null) ? localId : serverId));
2011-09-13 14:55:26 -07:00
}
public String getLogName()
{
return (serverId == null) ? "SMS reply" : ("SMS id=" + serverId);
}
public String getServerId()
{
return serverId;
}
public void setServerId(String id)
{
this.serverId = id;
}
public String getMessageBody()
{
return message;
}
public void setMessageBody(String message)
{
this.message = message;
}
public String getFrom()
{
return from;
}
public void setFrom(String from)
{
this.from = from;
}
public String getTo()
{
return to;
}
public void setTo(String to)
{
this.to = to;
}
public void retryNow() {
app.log("Retrying sending " + getLogName() + " to " + getTo());
trySend();
}
public void trySend()
{
SmsManager smgr = SmsManager.getDefault();
Intent intent = new Intent(app, MessageStatusNotifier.class);
2011-09-17 18:38:16 -07:00
intent.setData(this.getUri());
2011-09-13 14:55:26 -07:00
PendingIntent sentIntent = PendingIntent.getBroadcast(
app,
2011-09-13 14:55:26 -07:00
0,
intent,
PendingIntent.FLAG_ONE_SHOT);
smgr.sendTextMessage(getTo(), null, getMessageBody(), sentIntent, null);
}
protected Intent getRetryIntent() {
Intent intent = new Intent(app, OutgoingMessageRetry.class);
2011-09-17 18:38:16 -07:00
intent.setData(this.getUri());
2011-09-13 14:55:26 -07:00
return intent;
}
}