Thanks. I could have sworn I had tried the following and gotten
errors but it is exactly what worked. I can now change the ringer
mode of the phone. For others looking for the same idea, use the
following snippet:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
public class ToRing extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
AudioManager am = (AudioManager)
context.getSystemService(Context.AUDIO_SERVICE);
}
}
On Jan 9, 7:02 am, Mark Murphy <[email protected]> wrote:
> BroadcastReceiver does not inherit from Context. AUDIO_SERVICE is a
> constant on Context. getSystemService() is a method on Context. Hence,
> you need to adjust your code to use the Context class and supplied
> Context object.
>
>
>
>
>
>
>
>
>
> On Sat, Jan 8, 2011 at 9:01 PM, rsnider19 <[email protected]> wrote:
> > I am using an AlarmManager to trigger the following class so it will
> > change the volume from say high to low:
>
> > package com.test;
>
> > import android.content.BroadcastReceiver;
> > import android.content.Context;
> > import android.content.Intent;
> > import android.media.AudioManager;
>
> > public class ToRing extends BroadcastReceiver {
> > �...@override
> > public void onReceive(Context context, Intent intent) {
> > AudioManager am =
> > (AudioManager)getSystemService(AUDIO_SERVICE);
> > }
> > }
>
> > It is saying that AUDIO_SERVICE cannot be resolved to a constant or
> > variable. How can I access the audio service from within the
> > broadcast receiver?
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.> To post to this group, send email
> > [email protected]
> > To unsubscribe from this group, send email
> > to>[email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> Mark Murphy (a Commons
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> _The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9
> Available!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en