>
> Hi,
>
> I want to send RINGER_MODE update to an activity using an alarm
> manager and a BroadcastReceiver.
>
> So, in the file which is listening to
> "android.media.EXTRA_RINGER_MODE", I have this :
>
> if(intent.getAction().equals("android.media.RINGER_MODE_CHANGED")) {
>                               myAudio.setRingerMode(intent.getIntExtra
> ("android.media.EXTRA_RINGER_MODE", -1));
>                               System.out.println("Changement de son: "  + 
> Intent.getIntExtra
> ("android.media.EXTRA_RINGER_MODE", -1));
>                               System.out.println("bla : " + getRingerMode());
>                               sendRingerModeChangedBroadcast(getRingerMode());
>                       }
>
> ...
>
> Intent i = new Intent("com.tests.AudioInfo.RINGER_MODE_CHANGED");
>                       i.putExtra("myMode", newMode);
>                       PendingIntent broadcastSender = 
> PendingIntent.getBroadcast(context,
> 0, i, 0);
>                       am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
> SystemClock.elapsedRealtime(), broadcastSender);
>                       System.out.println("here: " + i.getIntExtra("myMode", 
> 55));
> ...
>
>
> And then in another file which receives it, I have :
>
> public void onReceive(Context context, Intent intent) {
> ...
>    else if(intent.getAction().equals
> ("com.tests.AudioInfo.RINGER_MODE_CHANGED")) {
>                               int newMode = intent.getIntExtra("myMode", 55);
>                               System.out.println("there: " + newMode);
>                               System.out.println("Ringer mode changed: " + 
> intent.getIntExtra
> ("myMode", 55));
>    }
>
>
> So in "here:" and "there:" I should have the same value.
> It works when this function is called for the first time but after,
> "here:" is always followed by the new values whereas "there:" is
> followed by the first value.
> So the line int newMode = intent.getIntExtra("myMode", 55);  does not
> work anymore.
>
> Could you explain to me why?

You need to cancel your PendingIntent after it is used. Otherwise, Android
will ignore your new PendingIntent and will keep using the old one (since
the Intent matches on things like action and so on).

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
Android App Developer Books: http://commonsware.com/books.html



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to