React on incoming mail

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

React on incoming mail

Postby Helios » Wed Feb 11, 2009 5:49 pm

Hi every one, I'm trying to make an application react on an incoming mail. Does anyone know if this is possible and if it is so where I can find an example? I have search and tried many different alternatives but I haven't accomplished my objective. Thanks in advance.

Regards,
Helios
Helios
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 17, 2009 7:11 am

Top

React on incoming mail

Postby Helios » Tue Feb 24, 2009 4:55 pm

Hi, on the sdk 1.1 release notes says:

The Settings and Email applications are now included in the SDK and available in the emulator.

Does any one knows if is possible and/or how to react to an incoming email? With this sdk version I am able to receive notifications of new emails using the mail application on the emulator (having an account configured in this app). As the notification is the same type as an SMS notification and because in the SmsMessage class has methods to handdle email messages I believe this should be possible. Does any one knows something about this?
Helios
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 17, 2009 7:11 am

Postby abraxas » Wed Feb 25, 2009 1:45 am

You could register a Broadcast and catch the Incoming call ACTION.
abraxas
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Feb 06, 2009 12:33 pm

Postby Helios » Fri Feb 27, 2009 7:28 pm

Thanks for your answer. Could you explain me in a little more detailed way how would try to do it please? I tried using the following code. What could be wrong?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class Receptor_SMS extends BroadcastReceiver
  3.  
  4. {
  5.  
  6.     @Override
  7.  
  8.     public void onReceive(Context context, Intent intent)
  9.  
  10.     {
  11.  
  12.         Bundle bundle = intent.getExtras();
  13.  
  14.  
  15.  
  16.         Object messages[] = (Object[]) bundle.get("pdus");
  17.  
  18.         SmsMessage smsMessage[] = new SmsMessage[messages.length];
  19.  
  20.         for (int n = 0; n < messages.length; n++)
  21.  
  22.        {
  23.  
  24.         smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
  25.  
  26.         }
  27.  
  28.        
  29.  
  30.         if (smsMessage[0].isEmail() == true)
  31.  
  32.         {
  33.  
  34.                 Toast toast = Toast.makeText(context, "eMail Recived", Toast.LENGTH_LONG);
  35.  
  36.                         toast.show();
  37.  
  38.         }
  39.  
  40.         String mensage = smsMessage[0].getMessageBody();
  41.  
  42.     }
  43.  
  44. }
  45.  
  46.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


I'm guessing that if the message received was an email, the isEmal method would detect that but the broadcastreceiver was never activated when an email was received. Thanks in advance.

Regards,
Helios
Helios
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 17, 2009 7:11 am

Postby abraxas » Fri Feb 27, 2009 8:16 pm

Your broadcastReceiver's onReceive Method will be only called if you have registered your broadcastReceiver within your manifest file.

Between intent-filter tags you can specify for which actions your broadcastReceiver should be informed.
Note that your onReceive Method must complete within 5 secs not to get a forced close warning!

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  2.  
  3. <application>
  4.  
  5.       ...
  6.  
  7. <receiver android:name="YourBroadcastReceiverClass">
  8.  
  9.   <intent-filter>
  10.  
  11.     <action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
  12.  
  13.   </intent-filter>
  14.  
  15. </receiver>
  16.  
  17.    ...
  18.  
  19. </application>
  20.  
  21.  
  22.  
  23. </manifest>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


The sample action is for SMS receiving notification. However, I do not know by heart how the action is called for eMail received. You have to look it up.
abraxas
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Feb 06, 2009 12:33 pm

Postby Helios » Fri Feb 27, 2009 8:29 pm

Thanks again for your answer. I already have my manifest configured as you say. I use the code I posted to receive SMS. I look up the message API and I found the isEmail method in the message class API so I guessed that you can do catch the Email messages the same way as the SMS. Like that one there are more parallel methods for SMS and Emails in that class. What do you mean by how the ACTION is called? Any other idea? Thanks in advance.

Regards,
Helios
Helios
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 17, 2009 7:11 am

Top

Postby abraxas » Fri Feb 27, 2009 8:39 pm

The email application sends a broadcast (to all who are interested in) when it receives a new mail.

This broadcast is meant an action and when you know the name of this Action which is for SMS notification "android.provider.Telephony.SMS_RECEIVED" you will get informed by Android if you have the action named within your intent-filter of your receiver.
abraxas
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Feb 06, 2009 12:33 pm

Postby Helios » Fri Feb 27, 2009 9:22 pm

Thanks again for your quick answer. I have looked for an action that permits my broadcastreceiver react on an incoming mail but I didn't find any one that fits. I have been trying to react on an incoming email for while now but I haven't been able. Do you think that this action exists? Do you have an idea of how this action might be called? Thanks in advance for all your help.

Regards,
Helios
Helios
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 17, 2009 7:11 am

Postby abraxas » Sat Feb 28, 2009 12:11 am

Receiving eMails is absolutely application dependent. I am not sure if goolges email app does broadcast an action to inform other apps.

I had a quick look at the google email app, but found no sendBroadcast() call. However, I had not looked in detail.

If you want to look by yourself visit
http://android.git.kernel.org/?p=platform/packages/apps/Email.git;a=summary
download the source with git and search for it.

But I am not even sure if email receiving is implemented in this package.
abraxas
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Feb 06, 2009 12:33 pm

Postby Helios » Sat Feb 28, 2009 3:00 am

Thanks again for your answer, is very helpful. I'll sure be looking at the code. There is one detail, cause I am testing my applications on the emulator and the default email didn't worked when I tried sending emails from the code so I installed the K-9 email app to do so. The thing is I don't know precisely which app shows the received email alert. If the email app does not send a broadcaste signal do you think is possible to do what I want? Thanks in advance.

Regards,
Helios
Helios
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 17, 2009 7:11 am

Postby Nemat » Fri Sep 25, 2009 8:27 am

Hi Helios.....

I m looking for the same thing.Have you done it????

Actually my application has to get notified when an incoming email is received.

Is it possible to do this in Android....?

Thanx in Advance
Nemat
Nemat
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Thu Aug 21, 2008 3:16 pm
Location: Jaipur

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 3 guests