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. Resuming a Large File Download

I am trying to implement the functionality to resume a large file
download, but have not found how to start downloading from a position
that is not at the beginning of an InputStream.  I am currently using
the InputStream.skip() method to go to the position where I want to
resume the download, but have found that this method actually reads
all the data over the network and then throws it away.

I would appreciate some help in learning the correct way to start
reading from the resume offset of the internet file being downloaded,
so that I can avoid wasting the phone network bandwidth, and also
avoid the extra time delay caused by re-downloading all the data that
was already previously downloaded.

My current code is as follows:

                File file = new File(mLocalFileName);
                URL url = new URL(mInternetFileName);
                URLConnection connection = url.openConnection();
                connection.connect();
                mInternetFileSize = connection.getContentLength();
                if (!file.exists()) {
                        file.createNewFile();
                        mLocalFileSize = 0;
                } else {
                        mLocalFileSize = file.length();
                }
                InputStream inputStream = connection.getInputStream();
                if (mLocalFileSize > 0) {
                        long amountSkipped = 0;
                        do {
                                amountSkipped += inputStream.skip(
                                                mLocalFileSize - amountSkipped);
                        } while (amountSkipped < mLocalFileSize);
                }
                FileOutputStream outputStream = new FileOutputStream(file,
                                mLocalFileSize > 0);
                byte buffer[] = new byte[2048];
                do {
                        int bytesRead = inputStream.read(buffer);
                        if (bytesRead <= 0) {
                                break;
                        }
                        outputStream.write(buffer, 0, bytesRead);
                        mLocalFileSize += bytesRead;
                } while (!mCancelDownloads);
                inputStream.close();
                outputStream.close();



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

2. eclipse dev question really

i've got multiple workspaces and one of them is not android.

but when i switch to that workspace - it tells me that the android
sdk is not available (i entered a folder that no longer is there) and
looks like it tries to start adb.

is there anyway in eclipse - that for this workspace, do not
attempt to initialize the android plugin - and resulting in trying
to find the sdk folder and load adb.

for this particialar workspace - i do not want anything android.

thanks.

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

3. 1.6 SDK Arrow keys (dpad/trackball) dir not changing with orientation?

4. Emulator dd command

5. Android Positions - Northern Virginia

6. Can Android use an external Bluetooth GPS unit?

7. problem in checkbox....