title: Exception on getSystemService(Context.AUDIO_SERVICE)
body: <p>I wanted to create an app that drops an incoming call based on some settings, that seems to be impossible on Android 1.6. So I decided to write an app that changes the Ringer to mute when the call would've been dropped. The thing is that when I call getSystemService(Context.AUDIO_SERVICE) I get an exception.</p>
  
  <p>These are my classes:</p>
  
  <p>CallReceiver</p>
  
  <pre><code>public class CallReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          MyPhoneStateListener phoneListener = new MyPhoneStateListener();
          TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
          telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);      
      }
  
  }
  </code></pre>
  
  <p>MyPhoneStateListener</p>
  
  <pre><code>public class MyPhoneStateListener extends PhoneStateListener {
  
      public void onCallStateChanged(int state, String incomingNumber){
  
          if (state == TelephonyManager.CALL_STATE_RINGING)
          {
              Log.d("DEBUG", "RINGING");
              (new TMLService()).ManageIncomingCall(incomingNumber);
          }
      }
  
  }
  </code></pre>
  
  <p>And there is a class called TMLService that extends Service which contains this method</p>
  
  <pre><code>public void ManageIncomingCall(String incomingNumber)  
  {
      super.onCreate();
      AudioManager audioManage = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
      audioManage.setRingerMode(AudioManager.RINGER_MODE_SILENT);
  }
  </code></pre>
  
  <p>Like I said, when I call AudioManager audioManage = (AudioManager)getSystemService(Context.AUDIO_SERVICE); the application stops and this is what I get in the LogCat:</p>
  
  <pre><code>D/DEBUG   (  356): RINGING
  D/AndroidRuntime(  356): Shutting down VM
  W/dalvikvm(  356): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
  E/AndroidRuntime(  356): Uncaught handler: thread main exiting due to uncaught exception
  D/CallNotifier(  103): RINGING... (new)
  E/AndroidRuntime(  356): java.lang.NullPointerException
  E/AndroidRuntime(  356):    at android.content.ContextWrapper.getSystemService(ContextWrapper.java:335)
  E/AndroidRuntime(  356):    at tml.v1.Service.TMLService.ManageIncomingCall(TMLService.java:94)
  E/AndroidRuntime(  356):    at tml.v1.Service.MyPhoneStateListener.onCallStateChanged(MyPhoneStateListener.java:14)
  E/AndroidRuntime(  356):    at android.telephony.PhoneStateListener$2.handleMessage(PhoneStateListener.java:298)
  E/AndroidRuntime(  356):    at android.os.Handler.dispatchMessage(Handler.java:99)
  E/AndroidRuntime(  356):    at android.os.Looper.loop(Looper.java:123)
  E/AndroidRuntime(  356):    at android.app.ActivityThread.main(ActivityThread.java:4203)
  E/AndroidRuntime(  356):    at java.lang.reflect.Method.invokeNative(Native Method)
  E/AndroidRuntime(  356):    at java.lang.reflect.Method.invoke(Method.java:521)
  E/AndroidRuntime(  356):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
  E/AndroidRuntime(  356):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
  E/AndroidRuntime(  356):    at dalvik.system.NativeStart.main(Native Method)
  D/CallNotifier(  103): onNewRingingConnection(): incoming
  </code></pre>