I want to implement a audio manager, but I can't quite figure out which class to put it in. If I put in onCreate, I can't refer to it, but if I put it in my Broadcast Receiver class, it can't find the getBaseContext() method. In the code below, it can't find the getBaseContext() method:
class SmsFilter extends BroadcastReceiver {
private final String TAG = "SMS";
public final AudioManager am = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null){
String action = intent.getAction();
if (action.equals("android.provider.Telephony.SMS_RECEIVED")){
Bundle extras = intent.getExtras();
if (extras != null){
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
}
}
}
}