Hi All, I have been working on BroadcastReceiver code to capture GMAIL events and try to extract data to create an email event log.
Although the registration of the BroadcastReceiver using Intent.PROVIDER_CHANGED for gmail appears to be correctly formed and no exceptions are generated. I have my doubts whether the receiver is able to capture gmail event for Intent.PROVIDER_CHANGED, generated when unread email is available, since code in my BroadcastReceiver is never activated. Upon reading the BroadcastReciever API docs (see excerpt below) I see that BroadcastReceivers are not designed to capture intents used with startActivity() and that BroadcastReceivers only receive intents generated from a sendBroadcast() method call. For your reference see my code snippets below. Is the BroadcastReceiver mechanism not the appropriate method to capture email/gmail/sms events? BroadcastReceiver code is the following: public class EmailReceiver extends BroadcastReceiver { /** * */ String TAG= "MY_TAG:RECEIVER"; @Override public void onReceive(Context context, Intent intent) { // Log.i(TAG, "Action=" + intent.getAction()); if (Intent.ACTION_PROVIDER_CHANGED.equals (intent.getAction ())) { Uri dataURI= intent.getData(); String dataURIPath=dataURI.getPath(); Log.i(TAG, dataURIPath); } } } BroadcastReceiver code registration for gmail is the following: // @override public void onCreate(Bundle b){ .... EmailReceiver myMailReceiver = new EmailReceiver(); ...... } @Override public void onResume(){ super.onResume(); try{ IntentFilter mailFilter = new IntentFilter ( Intent.ACTION_PROVIDER_CHANGED, "content://gmail-ls/unread/^i"); // IntentFilter mailFilter = new IntentFilter ( Intent.ACTION_PROVIDER_CHANGED, "gmail-ls"); registerReceiver( myMailReceiver, mailFilter); Log.i(myMailReceiver.TAG, "MailReceiver registered"); }catch(Exception e){ Log.e(myMailReceiver.TAG, "Intent Filter malformed"); } } Excerpt from BroadcastReceiver Doc: Base class for code that will receive intents sent by sendBroadcast (). ........ ........ Note that, although the Intent class is used for sending and receiving these broadcasts, the Intent broadcast mechanism here is completely separate from Intents that are used to start Activities with Context.startActivity(). There is no way for a BroadcastReceiver to see or capture Intents used with startActivity(); likewise, when you broadcast an Intent, you will never find or start an Activity. These two operations are semantically very different: starting an Activity with an Intent is a foreground operation that modifies what the user is currently interacting with; broadcasting an Intent is a background operation that the user is not normally aware of. ......... Regards, KK --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "android-framework" group. To post to this group, send email to android-framework@googlegroups.com To unsubscribe from this group, send email to android-framework+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-framework?hl=en -~----------~----~----~----~------~----~------~--~---