summaryrefslogtreecommitdiff
path: root/workspace/BlaMail/src
diff options
context:
space:
mode:
authorLuke Miller <lgdmiller@hotmail.com>2010-11-02 18:49:52 +0000
committerLuke Miller <lgdmiller@hotmail.com>2010-11-02 18:49:52 +0000
commit1b34eb31837a176d8d021791e78ec81bb084ecc2 (patch)
treec56be69c57a933a0ed4ee97684cfcf156987e65f /workspace/BlaMail/src
parent135633efbdf209caf8495f9e873299282e8e5407 (diff)
Added functionality to reconnect to the inbox after the data connection has been lost. SMS notification is sent on connection and disconnection.
Diffstat (limited to 'workspace/BlaMail/src')
-rw-r--r--workspace/BlaMail/src/com/blatech/blamail/BlaMail.java50
1 files changed, 41 insertions, 9 deletions
diff --git a/workspace/BlaMail/src/com/blatech/blamail/BlaMail.java b/workspace/BlaMail/src/com/blatech/blamail/BlaMail.java
index 6e99a12..5c14e0a 100644
--- a/workspace/BlaMail/src/com/blatech/blamail/BlaMail.java
+++ b/workspace/BlaMail/src/com/blatech/blamail/BlaMail.java
@@ -32,7 +32,6 @@ package com.blatech.blamail;
import java.util.Properties;
-import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
@@ -49,7 +48,9 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
+import android.telephony.PhoneStateListener;
import android.telephony.SmsManager;
+import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
@@ -70,9 +71,39 @@ public class BlaMail extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
+
+ TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
- Thread t = new Thread(new Monitor());
- t.start();
+ PhoneStateListener listener = new PhoneStateListener() {
+ @Override
+ public void onDataConnectionStateChanged(int state){
+ Thread t = null;
+ try {
+ switch (state) {
+ case TelephonyManager.DATA_CONNECTED:
+ sendSMS("0000000000000000000", "07927278978", "Notification from blamail: blamail is up.");
+ t = new Thread(new Monitor());
+ t.start();
+ break;
+ case TelephonyManager.DATA_DISCONNECTED:
+ sendSMS("0000000000000000000", "07927278978", "Notification from blamail: blamail is down.");
+ if(t != null){
+ t.interrupt();
+ }
+ break;
+ }
+ } catch (AddressException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (MessagingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ };
+
+ // Register the listener wit the telephony manager
+ tm.listen(listener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
Button send = (Button) findViewById(R.id.send);
@@ -135,7 +166,7 @@ public class BlaMail extends Activity {
}
folder.open(Folder.READ_WRITE);
-
+
// Add messageCountListener to listen for new messages
folder.addMessageCountListener(new MessageCountAdapter() {
public void messagesAdded(MessageCountEvent ev) {
@@ -156,12 +187,13 @@ public class BlaMail extends Activity {
IMAPFolder f = (IMAPFolder)folder;
for(;;){
- f.idle();
- }
+ f.idle();
+ }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
+ } catch (MessagingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
}