Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new pull request #3

Open
wants to merge 70 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
4130593
polling
niryariv Jan 15, 2011
aee1061
initial import of polling code
niryariv Jan 15, 2011
8e31033
new icon
niryariv Jan 15, 2011
ec1dc62
simplify polling UI to use fixed, 15 min intervals
niryariv Jan 15, 2011
2089450
cleanup home screen text
niryariv Jan 16, 2011
3ed1958
add a poll=true parameter
niryariv Jan 16, 2011
448eafe
Move post-parse sms sending to TargetUrlRequest
niryariv Jan 18, 2011
9473ab1
use POST in http requests; use different url for outgoing sms; poll f…
Sep 11, 2011
fc6cda4
do http requests in AsyncTask so they don't freeze the UI thread; imp…
Sep 12, 2011
8f15a8c
add menu with options to test server connection, or edit settings
Sep 12, 2011
d5b9734
fix null pointer exception; remove dependency on Base64 for android 1…
Sep 12, 2011
cb8d95e
PHP server library with example implementation; add 'check now' butto…
Sep 12, 2011
aff22e5
use string status codes instead of integers
Sep 13, 2011
0a0f50a
fix comments for php server example
Sep 13, 2011
da334a0
remove test action to simplify server implementation; add icons from …
Sep 13, 2011
307f354
add help screen
Sep 13, 2011
2911111
keep messages waiting to be sent in memory; if forwarding fails (in e…
Sep 13, 2011
d29e7b2
start alarm to poll for outgoing messages when phone boots; add optio…
Sep 13, 2011
e4cea3b
use alarm to schedule retries; fix bug where sms notfications were dr…
Sep 13, 2011
bead453
set phone number and api version as regular post fields instead of cu…
Sep 13, 2011
e535266
instead of deleting messages from inbox, prevent them from getting th…
Sep 13, 2011
e79fe7c
refactoring
Sep 13, 2011
61d24b2
add setting to enable/disable sms gateway
Sep 13, 2011
41141fa
add menu option to forward existing messages from inbox (delivered wh…
Sep 14, 2011
0071efd
improve ForwardInbox with help from http://www.marvinlabs.com/2010/10…
Sep 14, 2011
2f22c29
github generated gh-pages branch
youngj Sep 15, 2011
e78598c
refactor App to subclass Application; retain log messages in App clas…
Sep 15, 2011
46710c2
organize code into subpackages
Sep 16, 2011
60d4941
launching Main activity on boot is no longer necessary
Sep 16, 2011
d994b10
support for incoming MMS
Sep 18, 2011
72a893e
Merge branch 'gh-pages' of github.com:youngj/KalSMS
Sep 18, 2011
7bc88cf
updated readme
Sep 18, 2011
e834488
avoid exceeding Android limit of 100 outgoing SMS/app/hour; allow eff…
Sep 18, 2011
d720412
most README content moved to http://youngj.github.com/KalSMS/
Sep 19, 2011
430aeca
enable user to change wifi sleep policy on kalsms settings page for c…
Sep 19, 2011
3357de7
assume http:// scheme for server URLs
Sep 19, 2011
eb80837
add test mode to allow testing KalSMS on a phone that is also being u…
Sep 19, 2011
a793a5f
use http connection pooling to improve performance (especially over ssl)
Sep 20, 2011
9a574b3
add foreground service to keep App in memory (otherwise rate-limiting…
Sep 20, 2011
9440fdb
android's ForegroundService example code is surprisingly buggy
Sep 20, 2011
4b0010f
display version number
Sep 20, 2011
687400f
use kalsms version code in http requests
Sep 20, 2011
b6a372d
avoid forwarding sms from network; unregister mms observer when kalsm…
Sep 21, 2011
dbf3536
update url in readme
Sep 21, 2011
73bc3c9
MMS fixes: prevent httpclient from using transfer-encoding: chunked s…
Sep 22, 2011
7df89cd
rename to EnvayaSMS; add icon
Sep 22, 2011
1cf69e8
update links
Sep 23, 2011
6384942
handle sending and receiving multipart sms messages > 160 chars
Sep 24, 2011
986b50f
fix bug where outgoing sms would be cut off if they contain xml entities
Sep 25, 2011
bf14f23
fix encoding problem for post requests, make test a separate action
Sep 27, 2011
03d5f55
update php server library and example
Sep 27, 2011
faffc6c
don't request delivery reports but leave option open in future; fix b…
Sep 28, 2011
3108512
keep backlogged outgoing messages in priority queue; allow server to …
Sep 28, 2011
1081f57
automatic failover between wifi/mobile if server cannot be reached; s…
Sep 29, 2011
d7f803e
add PendingMessages activity for viewing/retrying/deleting pending me…
Oct 1, 2011
cf1deec
queue incoming messages like outgoing messages
Oct 1, 2011
dedfdb5
improve performance of displaying log in Main activity
Oct 1, 2011
79ec4c1
add note about local.properties and sdk.dir to README
Oct 4, 2011
af1f8af
add html page for simulating EnvayaSMS requests
Oct 9, 2011
f253f54
update license and readme files for request simulator
Oct 9, 2011
2889bf9
send new log messages to server on each HTTP request; notify server o…
Oct 10, 2011
f430ddb
set http user-agent header
Nov 13, 2011
22f8c26
add settings screen for ignored phone numbers; allow user to specify …
Nov 26, 2011
c18a28b
enable long polling - increase socket timeout, start only one PollerT…
Nov 30, 2011
6f19970
increment version to 2.0.4
Nov 30, 2011
d93ff76
update httpserver submodule to latest version
youngj Mar 15, 2012
f53ccc3
add support for incoming call notifications; fix intermittent NullPoi…
youngj Mar 16, 2012
239ee1f
version 3.0 - real-time AMQP connections; change server API format f…
youngj Apr 4, 2012
9d65fc1
remove stray references to telerivet
youngj Apr 4, 2012
69a05ac
remove code added for debugging
youngj Apr 4, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
send new log messages to server on each HTTP request; notify server o…
…f changes in device status (currently power/battery state)
Jesse Young committed Oct 10, 2011
commit 2889bf9b4b927b7056eb2ec01c91ebc7bbb58af5
17 changes: 13 additions & 4 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.envaya.sms"
android:versionCode="13"
android:versionName="2.0">
android:versionCode="14"
android:versionName="2.0.1">

<uses-sdk android:minSdkVersion="4" />

@@ -105,17 +105,26 @@
</intent-filter>
</receiver>

<receiver android:name=".receiver.ConnectivityChangeReceiver" >
<receiver android:name=".receiver.ConnectivityChangeReceiver" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>

<receiver android:name=".receiver.DeviceStatusReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
<action android:name="android.intent.action.BATTERY_LOW" />
<action android:name="android.intent.action.BATTERY_OKAY" />
</intent-filter>
</receiver>

<service android:name=".CheckMmsInboxService">
</service>

<service android:name=".ForegroundService">
</service>

</application>
</application>
</manifest>
24 changes: 23 additions & 1 deletion server/php/EnvayaSMS.php
Original file line number Diff line number Diff line change
@@ -11,12 +11,18 @@ class EnvayaSMS
const ACTION_INCOMING = 'incoming';
const ACTION_OUTGOING = 'outgoing';
const ACTION_SEND_STATUS = 'send_status';
const ACTION_DEVICE_STATUS = 'device_status';
const ACTION_TEST = 'test';

const STATUS_QUEUED = 'queued';
const STATUS_FAILED = 'failed';
const STATUS_SENT = 'sent';

const DEVICE_STATUS_POWER_CONNECTED = "power_connected";
const DEVICE_STATUS_POWER_DISCONNECTED = "power_disconnected";
const DEVICE_STATUS_BATTERY_LOW = "battery_low";
const DEVICE_STATUS_BATTERY_OKAY = "battery_okay";

const MESSAGE_TYPE_SMS = 'sms';
const MESSAGE_TYPE_MMS = 'mms';

@@ -49,11 +55,13 @@ class EnvayaSMS_Request

public $version;
public $phone_number;
public $log;

function __construct()
{
$this->version = $_POST['version'];
$this->phone_number = $_POST['phone_number'];
$this->log = @$_POST['log'];
}

function get_action()
@@ -77,6 +85,8 @@ private function _get_action()
return new EnvayaSMS_Action_SendStatus($this);
case EnvayaSMS::ACTION_TEST:
return new EnvayaSMS_Action_Test($this);
case EnvayaSMS::ACTION_DEVICE_STATUS:
return new EnvayaSMS_Action_DeviceStatus($this);
default:
return new EnvayaSMS_Action($this);
}
@@ -247,4 +257,16 @@ function __construct($request)
$this->id = $_POST['id'];
$this->error = $_POST['error'];
}
}
}

class EnvayaSMS_Action_DeviceStatus extends EnvayaSMS_Action
{
public $status; // EnvayaSMS::DEVICE_STATUS_* values

function __construct($request)
{
parent::__construct($request);
$this->type = EnvayaSMS::ACTION_DEVICE_STATUS;
$this->status = $_POST['status'];
}
}
1 change: 1 addition & 0 deletions server/php/example/log/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.log
14 changes: 14 additions & 0 deletions server/php/example/www/index.php
Original file line number Diff line number Diff line change
@@ -22,6 +22,16 @@
return;
}

// append to EnvayaSMS app log
$app_log = $request->log;
if ($app_log)
{
$log_file = dirname(__DIR__)."/log/sms_".preg_replace('#[^\w]#', '', $request->phone_number).".log";
$f = fopen($log_file, "a");
fwrite($f, $app_log);
fclose($f);
}

$action = $request->get_action();

switch ($action->type)
@@ -79,6 +89,10 @@
echo "invalid id";
}
return;
case EnvayaSMS::ACTION_DEVICE_STATUS:
error_log("device_status = {$action->status}");
echo "OK";
return;
case EnvayaSMS::ACTION_TEST:
echo "OK";
return;
22 changes: 20 additions & 2 deletions server/php/example/www/test.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>

<title>EnvayaSMS Request Simulator</title>
<style type='text/css'>
body
{
@@ -30,10 +30,12 @@ <h2>EnvayaSMS Request Simulator</h2>
<tr><th>Server URL</th><td><input id='server_url' type='text' size='40' /></td></tr>
<tr><th>Phone Number</th><td><input id='phone_number' type='text' /></td></tr>
<tr><th>Password</th><td><input id='password' type='password' /></td></tr>
<tr><th>Log Messages</th><td><textarea id='log' style='width:250px'></textarea></td></tr>
<tr><th>Action</th><td><select id='action' onchange='actionChanged()' onkeypress='actionChanged()'>
<option value='incoming'>incoming</option>
<option value='outgoing'>outgoing</option>
<option value='send_status'>send_status</option>
<option value='device_status'>device_status</option>
<option value='test'>test</option>
</select></td></tr>
</table>
@@ -46,7 +48,7 @@ <h4>Parameters for action=incoming:</h4>
<option value='sms'>sms</option>
<option value='mms'>mms</option>
</select></td></tr>
<tr><th>Message</th><td><textarea id='message'></textarea></td></tr>
<tr><th>Message</th><td><textarea id='message' style='width:250px'></textarea></td></tr>
<tr><th>Timestamp</th><td><input id='timestamp' type='text' /></td></tr>
</table>
</div>
@@ -70,6 +72,17 @@ <h4>Parameters for action=send_status:</h4>
<h4>Parameters for action=test:</h4>
(None)
</div>
<div id='action_device_status' style='display:none'>
<h4>Parameters for action=device_status:</h4>
<table class='smsTable'>
<tr><th>Status</th><td><select id='device_status'>
<option value='power_connected'>power_connected</option>
<option value='power_disconnected'>power_disconnected</option>
<option value='battery_low'>battery_low</option>
<option value='battery_okay'>battery_okay</option>
</select></td></tr>
</table>
</div>


<script type='text/javascript'>
@@ -100,6 +113,7 @@ <h4>Parameters for action=test:</h4>
version: '13',
phone_number: $('phone_number').value,
action: action,
log: $('log').value
};

if (action == 'incoming')
@@ -115,6 +129,10 @@ <h4>Parameters for action=test:</h4>
params.status = $('status').value;
params.error = $('error').value;
}
else if (action == 'device_status')
{
params.status = $('device_status').value;
}

var xhr = (window.ActiveXObject && !window.XMLHttpRequest) ? new ActiveXObject("Msxml2.XMLHTTP") : new XMLHttpRequest();

80 changes: 72 additions & 8 deletions src/org/envaya/sms/App.java
Original file line number Diff line number Diff line change
@@ -26,8 +26,10 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import org.apache.http.client.HttpClient;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
@@ -41,6 +43,7 @@
import org.apache.http.params.HttpProtocolParams;
import org.envaya.sms.receiver.OutgoingMessagePoller;
import org.envaya.sms.receiver.ReenableWifiReceiver;
import org.envaya.sms.task.HttpTask;
import org.envaya.sms.task.PollerTask;
import org.json.JSONArray;
import org.json.JSONException;
@@ -50,12 +53,18 @@ public final class App extends Application {
public static final String ACTION_OUTGOING = "outgoing";
public static final String ACTION_INCOMING = "incoming";
public static final String ACTION_SEND_STATUS = "send_status";
public static final String ACTION_DEVICE_STATUS = "device_status";
public static final String ACTION_TEST = "test";

public static final String STATUS_QUEUED = "queued";
public static final String STATUS_FAILED = "failed";
public static final String STATUS_SENT = "sent";

public static final String DEVICE_STATUS_POWER_CONNECTED = "power_connected";
public static final String DEVICE_STATUS_POWER_DISCONNECTED = "power_disconnected";
public static final String DEVICE_STATUS_BATTERY_LOW = "battery_low";
public static final String DEVICE_STATUS_BATTERY_OKAY = "battery_okay";

public static final String MESSAGE_TYPE_MMS = "mms";
public static final String MESSAGE_TYPE_SMS = "sms";

@@ -114,6 +123,8 @@ public final class App extends Application {
public final Inbox inbox = new Inbox(this);
public final Outbox outbox = new Outbox(this);

public final Queue<HttpTask> queuedTasks = new LinkedList<HttpTask>();

private SharedPreferences settings;
private MmsObserver mmsObserver;
private SpannableStringBuilder displayedLog = new SpannableStringBuilder();
@@ -427,10 +438,11 @@ public String getPassword() {
public synchronized void retryStuckMessages() {
outbox.retryAll();
inbox.retryAll();
retryQueuedTasks();
}

public synchronized int getPendingMessageCount() {
return outbox.size() + inbox.size();
public synchronized int getPendingTaskCount() {
return outbox.size() + inbox.size() + queuedTasks.size();
}

public void debug(String msg) {
@@ -439,8 +451,24 @@ public void debug(String msg) {

private int logEpoch = 0;

public synchronized void log(CharSequence msg)
private StringBuilder newLogBuffer = new StringBuilder();

public synchronized String getNewLogEntries()
{
String res = newLogBuffer.toString();
newLogBuffer.setLength(0);
return res;
}

// clients may sometimes unget log entries out of order,
// but most of the time this will be the right order
public synchronized void ungetNewLogEntries(String logEntries)
{
newLogBuffer.insert(0, logEntries);
}

public synchronized void log(CharSequence msg)
{
Log.d(LOG_NAME, msg.toString());

// prevent displayed log from growing too big
@@ -462,6 +490,8 @@ public synchronized void log(CharSequence msg)
logEpoch++;
}

int prevLength = displayedLog.length();

// display a timestamp in the log occasionally
long logTime = SystemClock.elapsedRealtime();
if (logTime - lastLogTime > LOG_TIMESTAMP_INTERVAL)
@@ -472,8 +502,10 @@ public synchronized void log(CharSequence msg)
}

displayedLog.append(msg);
displayedLog.append("\n");

displayedLog.append("\n");

newLogBuffer.append(displayedLog, prevLength, displayedLog.length());

sendBroadcast(new Intent(App.LOG_CHANGED_INTENT));
}

@@ -670,12 +702,23 @@ public synchronized void asyncCheckConnectivity()

if (activeNetwork == null || !activeNetwork.isConnected())
{
WifiManager wmgr = (WifiManager)getSystemService(Context.WIFI_SERVICE);
WifiManager wmgr = (WifiManager)getSystemService(Context.WIFI_SERVICE);

if (activeNetwork != null)
{
log(activeNetwork.getTypeName() + "=" + activeNetwork.getState());
}
else
{
log("Not connected to any network.");
}

if (!wmgr.isWifiEnabled() && isNetworkFailoverEnabled())
{
log("Enabling WIFI...");
wmgr.setWifiEnabled(true);
}

return;
}

@@ -799,7 +842,28 @@ private void onConnectivityRestored()
if (getOutgoingPollSeconds() > 0)
{
checkOutgoingMessages();
}
// failed outgoing message status notifications are dropped...
}

retryQueuedTasks();
}

public synchronized void retryQueuedTasks()
{
while (true)
{
HttpTask task = queuedTasks.poll();

if (task == null)
{
break;
}

task.execute();
}
}

public synchronized void addQueuedTask(HttpTask task)
{
queuedTasks.add(task);
}
}
11 changes: 7 additions & 4 deletions src/org/envaya/sms/Outbox.java
Original file line number Diff line number Diff line change
@@ -57,8 +57,8 @@ public Outbox(App app)
this.app = app;
}

private void notifyMessageStatus(OutgoingMessage sms, String status, String errorMessage) {
String serverId = sms.getServerId();
private void notifyMessageStatus(OutgoingMessage sms, final String status, final String errorMessage) {
final String serverId = sms.getServerId();

String logMessage;
if (status.equals(App.STATUS_SENT)) {
@@ -73,12 +73,15 @@ private void notifyMessageStatus(OutgoingMessage sms, String status, String erro
if (serverId != null) {
app.log("Notifying server " + smsDesc + " " + logMessage);

new HttpTask(app,
HttpTask task = new HttpTask(app,
new BasicNameValuePair("id", serverId),
new BasicNameValuePair("status", status),
new BasicNameValuePair("error", errorMessage),
new BasicNameValuePair("action", App.ACTION_SEND_STATUS)
).execute();
);
task.setRetryOnConnectivityError(true);
task.execute();

} else {
app.log(smsDesc + " " + logMessage);
}
53 changes: 53 additions & 0 deletions src/org/envaya/sms/receiver/DeviceStatusReceiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.envaya.sms.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import org.apache.http.message.BasicNameValuePair;
import org.envaya.sms.App;
import org.envaya.sms.task.HttpTask;

public class DeviceStatusReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
App app = (App) context.getApplicationContext();
if (!app.isEnabled())
{
return;
}

String action = intent.getAction();

String status = "";

if (Intent.ACTION_POWER_CONNECTED.equals(action))
{
status = App.DEVICE_STATUS_POWER_CONNECTED;
app.log("Power connected");
}
else if (Intent.ACTION_POWER_DISCONNECTED.equals(action))
{
status = App.DEVICE_STATUS_POWER_DISCONNECTED;
app.log("Power disconnected");
}
else if (Intent.ACTION_BATTERY_LOW.equals(action))
{
status = App.DEVICE_STATUS_BATTERY_LOW;
app.log("Battery low");
}
else if (Intent.ACTION_BATTERY_OKAY.equals(action))
{
status = App.DEVICE_STATUS_BATTERY_OKAY;
app.log("Battery okay");
}

HttpTask task = new HttpTask(app,
new BasicNameValuePair("action", App.ACTION_DEVICE_STATUS),
new BasicNameValuePair("status", status)
);
task.setRetryOnConnectivityError(true);
task.execute();
}
}
48 changes: 39 additions & 9 deletions src/org/envaya/sms/task/HttpTask.java
Original file line number Diff line number Diff line change
@@ -43,27 +43,40 @@ public class HttpTask extends AsyncTask<String, Void, HttpResponse> {

protected String url;
protected List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();

protected BasicNameValuePair[] paramsArr;

private List<FormBodyPart> formParts;
private boolean useMultipartPost = false;

private HttpPost post;
private String logEntries;

private boolean retryOnConnectivityError;

public HttpTask(App app, BasicNameValuePair... paramsArr)
{
super();
this.app = app;
this.url = app.getServerUrl();
params = new ArrayList<BasicNameValuePair>(Arrays.asList(paramsArr));
params.add(new BasicNameValuePair("version", "" + app.getPackageInfo().versionCode));
params.add(new BasicNameValuePair("phone_number", app.getPhoneNumber()));
this.app = app;
this.paramsArr = paramsArr;
params = new ArrayList<BasicNameValuePair>(Arrays.asList(paramsArr));
}

public void setRetryOnConnectivityError(boolean retry)
{
this.retryOnConnectivityError = retry;
}

protected HttpTask getCopy()
{
return new HttpTask(app, paramsArr);
}

public void setFormParts(List<FormBodyPart> formParts)
{
useMultipartPost = true;
this.formParts = formParts;
}
}

private String getSignature()
throws NoSuchAlgorithmException, UnsupportedEncodingException
@@ -97,12 +110,20 @@ public int compare(Object o1, Object o2)
return new String(Base64Coder.encode(digest));
}

protected HttpResponse doInBackground(String... ignored) {
protected HttpResponse doInBackground(String... ignored) {
url = app.getServerUrl();

if (url.length() == 0) {
app.log("Can't contact server; Server URL not set");
return null;
}

logEntries = app.getNewLogEntries();

params.add(new BasicNameValuePair("version", "" + app.getPackageInfo().versionCode));
params.add(new BasicNameValuePair("phone_number", app.getPhoneNumber()));
params.add(new BasicNameValuePair("log", logEntries));

post = new HttpPost(url);

try
@@ -145,31 +166,40 @@ protected HttpResponse doInBackground(String... ignored) {
else if (statusCode == 403)
{
response.getEntity().consumeContent();
app.ungetNewLogEntries(logEntries);
app.log("Failed to authenticate to server");
app.log("(Phone number or password may be incorrect)");
return null;
}
else
{
response.getEntity().consumeContent();
app.ungetNewLogEntries(logEntries);
app.log("Received HTTP " + statusCode + " from server");
return null;
}
}
}
catch (IOException ex)
{
post.abort();
app.ungetNewLogEntries(logEntries);
app.logError("Error while contacting server", ex);

if (ex instanceof UnknownHostException || ex instanceof SocketTimeoutException)
{
{
if (retryOnConnectivityError)
{
app.addQueuedTask(getCopy());
}

app.asyncCheckConnectivity();
}
return null;
}
catch (Throwable ex)
{
post.abort();
app.ungetNewLogEntries(logEntries);
app.logError("Unexpected error while contacting server", ex, true);
return null;
}
13 changes: 10 additions & 3 deletions src/org/envaya/sms/ui/Main.java
Original file line number Diff line number Diff line change
@@ -100,6 +100,13 @@ public void onCreate(Bundle savedInstanceState) {
registerReceiver(logReceiver, logReceiverFilter);
}

@Override
public void onDestroy()
{
this.unregisterReceiver(logReceiver);
super.onDestroy();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
@@ -140,9 +147,9 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem retryItem = menu.findItem(R.id.retry_now);
int pendingMessages = app.getPendingMessageCount();
retryItem.setEnabled(pendingMessages > 0);
retryItem.setTitle("Retry All (" + pendingMessages + ")");
int pendingTasks = app.getPendingTaskCount();
retryItem.setEnabled(pendingTasks > 0);
retryItem.setTitle("Retry All (" + pendingTasks + ")");

return true;
}
7 changes: 7 additions & 0 deletions src/org/envaya/sms/ui/PendingMessages.java
Original file line number Diff line number Diff line change
@@ -93,6 +93,13 @@ else if (which == 1)

refreshMessages();
}

@Override
public void onDestroy()
{
this.unregisterReceiver(refreshReceiver);
super.onDestroy();
}

public void refreshMessages()
{