Broadcast receivers

by Raj » Wed, 18 Nov 2009 22:57:08 GMT


Sponsored Links
 Hi

I would like to add my own listeners to broadcast receiver so that
when different SMS arrive with different subjects, I can notify the
respective listeners.

@Override
        public void onReceive(Context context, Intent intent) {
                Bundle bundle = intent.getExtras();

                Object messages[] = (Object[]) bundle.get("pdus");
                SmsMessage smsMessage[] = new SmsMessage[messages.length];
                for (int n = 0; n < messages.length; n++) {
                smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
                }

Intent broadcast = new Intent(context,ApiKeyMessageListener.class);
                                
broadcast.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                broadcast.putExtra("API_KEY", message);
                                context.startActivity(new Intent(broadcast));

--



Broadcast receivers

by Raj » Wed, 18 Nov 2009 22:57:11 GMT


 Hi

I would like to add my own listeners to broadcast receiver so that
when different SMS arrive with different subjects, I can notify the
respective listeners.

@Override
        public void onReceive(Context context, Intent intent) {
                Bundle bundle = intent.getExtras();

                Object messages[] = (Object[]) bundle.get("pdus");
                SmsMessage smsMessage[] = new SmsMessage[messages.length];
                for (int n = 0; n < messages.length; n++) {
                smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
                }

               Intent broadcast = new Intent
(context,ApiKeyMessageListener.class);
               broadcast.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
               broadcast.putExtra("API_KEY", message);
               context.startActivity(new Intent(broadcast));
       }

Basically I want to get reference to this BroadcastRecevier object and
add listeners to it.  How
do I get the object reference that is declared in AndroidManifest.xml

Or is there an alternative way to do this?

thanks
Raj

--


Sponsored Links


Broadcast Receivers

by pperotti » Thu, 22 Apr 2010 04:06:40 GMT


 Hi Everyone,

Can anyone give a hint if you know why there are some ACTIONS that do
not trigger their associated receivers when they are registered in the
manifest while they are received when they are register through
registerReceiver() ?

For instance, when I declare:

<receiver android:name=".MyReceiver">
    <intent-filter>
        <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
    </intent-filter>
</receiver>

if the application is NOT running MyReceiver is never invoked.

But now, if I register the intent from inside a service, MyReceiver is
invoked properly.

Any tip will be appreciated.

Regards, Pablo

--



Broadcast Receivers

by Mark Murphy » Thu, 22 Apr 2010 04:38:38 GMT


 


Usually, it's for performance reasons.

Take your desired Intent, for example. ACTION_NEW_OUTGOING_CALL is
something the user is particularly paying attention to. If Android has
to fire off a bunch of processes, load up the receivers, and pass the
Intent to each, that's going to slow down how quickly Android is able to
place the call.

Another example is ACTION_BATTERY_CHANGED -- they don't want to fire up
a bunch of processes just to tell apps that the battery level changed.
After all, firing off all those processes and doing all that work might
decrease the battery level, requiring another round of
ACTION_BATTERY_CHANGED, which will either eventually drain the battery
or create a rupture in the space-time continuum. I get those two cases
confused a lot.

Sometimes, Intents that do not support manifest-registered receivers are
documented, sometimes not.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android Training in US: 14-18 June 2010:  http://bignerdranch.com 

--



Other Threads

1. Problems of Android SDK 1.6 R1 in Windows 7

My environment is Windows 7 + JDK 1.6u16 + Eclipse Galileo SR1

After I create an Android project and I open the AndroidManifest.xml
with Android Layout Editor, the Layout Editor shows
"ClassNotFoundException:null" and the console shows the below
Exception:
java.lang.ClassNotFoundException
        at
com.android.ide.eclipse.adt.internal.resources.manager.ProjectClassLoader.findClass
(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at
com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView
(Unknown Source)
        at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:
198)
        at android.view.BridgeInflater.onCreateView(BridgeInflater.java:99)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:
562)
        at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:
122)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:296)
        at com.android.layoutlib.bridge.Bridge.computeLayout(Bridge.java:376)
        at
com.android.ide.eclipse.adt.internal.editors.layout.GraphicalLayoutEditor.computeLayout
(Unknown Source)
        at
com.android.ide.eclipse.adt.internal.editors.layout.GraphicalLayoutEditor.recomputeLayout
(Unknown Source)
        at
com.android.ide.eclipse.adt.internal.editors.layout.GraphicalLayoutEditor.activated
(Unknown Source)
        at
com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.pageChange
(Unknown Source)
        at org.eclipse.ui.part.MultiPageEditorPart.setActivePage
(MultiPageEditorPart.java:1076)
        at org.eclipse.ui.forms.editor.FormEditor.setActivePage
(FormEditor.java:601)
        at
com.android.ide.eclipse.adt.internal.editors.AndroidEditor.selectDefaultPage
(Unknown Source)
        at com.android.ide.eclipse.adt.internal.editors.AndroidEditor.addPages
(Unknown Source)
        at org.eclipse.ui.forms.editor.FormEditor.createPages(FormEditor.java:
138)
        at org.eclipse.ui.part.MultiPageEditorPart.createPartControl
(MultiPageEditorPart.java:357)
        at org.eclipse.ui.internal.EditorReference.createPartHelper
(EditorReference.java:662)
        at org.eclipse.ui.internal.EditorReference.createPart
(EditorReference.java:462)
        at org.eclipse.ui.internal.WorkbenchPartReference.getPart
(WorkbenchPartReference.java:595)
        at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:313)
        at org.eclipse.ui.internal.presentations.PresentablePart.setVisible
(PresentablePart.java:180)
        at
org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select
(PresentablePartFolder.java:270)
        at
org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select
(LeftToRightTabOrder.java:65)
        at
org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart
(TabbedStackPresentation.java:473)
        at org.eclipse.ui.internal.PartStack.refreshPresentationSelection
(PartStack.java:1256)
        at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:
1209)
        at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1608)
        at org.eclipse.ui.internal.PartStack.add(PartStack.java:499)
        at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:103)
        at org.eclipse.ui.internal.PartStack.add(PartStack.java:485)
        at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:112)
        at org.eclipse.ui.internal.EditorSashContainer.addEditor
(EditorSashContainer.java:63)
        at org.eclipse.ui.internal.EditorAreaHelper.addToLayout
(EditorAreaHelper.java:225)
        at org.eclipse.ui.internal.EditorAreaHelper.addEditor
(EditorAreaHelper.java:213)
        at org.eclipse.ui.internal.EditorManager.createEditorTab
(EditorManager.java:778)
        at org.eclipse.ui.internal.EditorManager.openEditorFromDescriptor
(EditorManager.java:677)
        at org.eclipse.ui.internal.EditorManager.openEditor
(EditorManager.java:638)
        at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched
(WorkbenchPage.java:2854)
        at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor
(WorkbenchPage.java:2762)
        at org.eclipse.ui.internal.WorkbenchPage.access$11(WorkbenchPage.java:
2754)
        at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:
2705)
        at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:
70)
        at org.eclipse.ui.internal.WorkbenchPage.openEditor
(WorkbenchPage.java:2701)
        at org.eclipse.ui.internal.WorkbenchPage.openEditor
(WorkbenchPage.java:2685)
        at org.eclipse.ui.actions.OpenWithMenu.openEditor(OpenWithMenu.java:
344)
        at org.eclipse.ui.actions.OpenWithMenu$2.handleEvent
(OpenWithMenu.java:192)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:
3880)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3473)
        at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:
2405)
        at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
        at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
        at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
        at org.eclipse.core.databinding.observable.Realm.runWithDefault
(Realm.java:332)
        at org.eclipse.ui.internal.Workbench.createAndRunWorkbench
(Workbench.java:493)
        at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:
149)
        at org.eclipse.ui.internal.ide.application.IDEApplication.start
(IDEApplication.java:113)
        at org.eclipse.equinox.internal.app.EclipseAppHandle.run
(EclipseAppHandle.java:194)
        at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication
(EclipseAppLauncher.java:110)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start
(EclipseAppLauncher.java:79)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run
(EclipseStarter.java:368)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run
(EclipseStarter.java:179)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1311)

----------------------------------------------------
Does anybody meet the same problem ? and how to resolve it ?
Thank you for your help.

--~--~---------~--~----~------------~-------~--~----~

2. where can we announce new application we create?

I've created Time Keeper, a new Android Application.  Does anyone know
where it would be appropriate to announce such things to the Android
developer community, or the public at large (e.g. an Android users
group or new applications announcement group).

Thanks.

--Richard

--~--~---------~--~----~------------~-------~--~----~

3. Can't download Paid Apps from Market

4. Android 1.6 SDK is here!

5. Problem in Video View

6. NullPointerException after stopping/resuming activity repeatedly

7. ExpandableListActivity issue