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. Correct way to measure a view

I wanted to know if I am doing this right? Or is there something that
I am missing?


I have created a custom view by extending the View class. The sole
purpose of the view is to display a Bitmap on the canvas. The Bitmap
to be displayed in View is supplied by the view-containing-activity
using a setter method, say setImage(Bitmap).I want the view to be
sized according to the Bitmap dimensions, something like a wrap
content and also to be displayed in the center of the Activity. So, in
the layout XML for the activity I have :

<LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:gravity="center">

                <MyView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/myView" />
</LinearLayout>

 Also, I have coded the onMeasure(..) for the view as:

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
if(mBitmap != null){
        setMeasuredDimension(
        mBitmap.getWidth(),
        mBitmap.getHeight());
        }
        else{
           Log.e(TAG,"Bitmap not initialized");
                }
}

Now when the screen orientation changes, I want to:
1. Resize the bitmap according to screen dimensions
2. Re-measure the view.

For this, I have coded the onSizeChanged(..) as:

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        // TODO Auto-generated method stub
        super.onSizeChanged(w, h, oldw, oldh);
        mBitmap = BitmapUtils.resizeBitmap(mBitmap, w, h);
}

When I run this code, everything works fine in Potrait mode: the view
is displayed in the center
However, in landscape mode, though the view is displayed in center,
the bitmap is not resized neither is the view re-measured. This is
probably because onSizeChanged is called after onMeasure(..). Maybe, I
could resize the Bitmap in the activity and them pass it to the View.






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

2. Developers Bewaandroid-leak.com - Android Warez Site

Streets Of Boston,

I mentioned both of those markets in my email.

My point was that many paid apps are still not available on them. I
can sit here and wave my 87p at Nicolas' Android Market entry till I'm
blue in the face, but I can't give a penny of it to him as long as it
doesn't let me.

On the other hand, the dark and evil pirates on RapidShare supply me
with the app I want with minimal fuss. The fact it costs nothing is
immaterial. Despite not being able to use his distribution method, I
would pay Nicolas a donation of the same amount he originally asked
for, except he doesn't accept donations.



On Wed, Sep 2, 2009 at 3:15 PM, Streets Of







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

3. Using Webkit/Webview for Android UI instead of native UI

4. ArrayAdapter also works with java.util.List (was ListView with Streaming Content)

5. XML Parser error

6. When I run getSize() on my text view it returns 0

7. Need Help : getheight()/width() API returning wrong screensize on device.