title: Can i make the profile in android to silent or normal in a service class
body: <p>Here i created a service to get the current location and when location changed i get the lat and lng and through geocoder i display the sub locality....
      is it possible to make the profile to silent if the user reaches a particular sublocality.
      I tried so but i am receiving a null pointer exception....
      can anybody help..i am new to android..</p>
  
  <pre><code>package com.secure.call_block;
      import java.io.IOException;
      import java.util.List;
      import java.util.Locale;
  
      import android.app.Service;
      import android.content.Context;
      import android.content.Intent;
      import android.location.Address;
      import android.location.Geocoder;
      import android.location.Location;
      import android.location.LocationManager;
      import android.media.AudioManager;
      import android.os.Bundle;
      import android.os.IBinder;
      import android.util.Log;
  
      public class MyService extends Service
      {
          Context context;
      private static final String TAG = "BOOMBOOMTESTGPS";
      private LocationManager mLocationManager = null;
      private static final int LOCATION_INTERVAL = 1000*8;
      private static final float LOCATION_DISTANCE = 10f;
  
      private class LocationListener implements android.location.LocationListener{
          Location mLastLocation;
          public LocationListener(String provider)
          {
              Log.e(TAG, "LocationListener " + provider);
              mLastLocation = new Location(provider);
          }
          @Override
          public void onLocationChanged(Location location)
          {
              Log.e(TAG, "onLocationChanged: " + location);
              mLastLocation.set(location);
  
              /*----------to get City-Name from coordinates ------------- */
              String cityName=null;                 
              Geocoder gcd = new Geocoder(getBaseContext(), Locale.getDefault());                  
              List&lt;Address&gt;  addresses;  
              try {  
               addresses = gcd.getFromLocation(location.getLatitude(), location.getLongitude(), 1);  
               if (addresses.size() &gt; 0)  
                System.out.println(addresses.get(0).getLocality());  
               Address address = addresses.get(0);
               cityName= address.getSubLocality();
               System.out.println("CCCCCCCCCIIIIIIIIIIIIITTTTTTTTTTTYYYYYY "+cityName);
              } catch (IOException e) {                 
               e.printStackTrace();  
              } 
  
  //i think i am having problem from here onwards....
              if(SetLocation.workcityName!=null)
              {
              if(SetLocation.workcityName.equalsIgnoreCase(cityName))
              {
                  AudioManager audiomanager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
                  audiomanager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
              }
              }
          }
          @Override
          public void onProviderDisabled(String provider)
          {
              Log.e(TAG, "onProviderDisabled: " + provider);            
          }
          @Override
          public void onProviderEnabled(String provider)
          {
              Log.e(TAG, "onProviderEnabled: " + provider);
          }
          @Override
          public void onStatusChanged(String provider, int status, Bundle extras)
          {
              Log.e(TAG, "onStatusChanged: " + provider);
          }
      } 
      LocationListener[] mLocationListeners = new LocationListener[] {
              new LocationListener(LocationManager.GPS_PROVIDER),
              new LocationListener(LocationManager.NETWORK_PROVIDER)
      };
      @Override
      public IBinder onBind(Intent arg0)
      {
          return null;
      }
      @Override
      public int onStartCommand(Intent intent, int flags, int startId)
      {
          Log.e(TAG, "onStartCommand");
          super.onStartCommand(intent, flags, startId);       
          return START_STICKY;
      }
      @Override
      public void onCreate()
      {
          Log.e(TAG, "onCreate");
          initializeLocationManager();
          try {
              mLocationManager.requestLocationUpdates(
                      LocationManager.NETWORK_PROVIDER, LOCATION_INTERVAL, LOCATION_DISTANCE,
                      mLocationListeners[1]);
          } catch (java.lang.SecurityException ex) {
              Log.i(TAG, "fail to request location update, ignore", ex);
          } catch (IllegalArgumentException ex) {
              Log.d(TAG, "network provider does not exist, " + ex.getMessage());
          }
          try {
              mLocationManager.requestLocationUpdates(
                      LocationManager.GPS_PROVIDER, LOCATION_INTERVAL, LOCATION_DISTANCE,
                      mLocationListeners[0]);
          } catch (java.lang.SecurityException ex) {
              Log.i(TAG, "fail to request location update, ignore", ex);
          } catch (IllegalArgumentException ex) {
              Log.d(TAG, "gps provider does not exist " + ex.getMessage());
          }
      }
      @Override
      public void onDestroy()
      {
          Log.e(TAG, "onDestroy");
          super.onDestroy();
          if (mLocationManager != null) {
              for (int i = 0; i &lt; mLocationListeners.length; i++) {
                  try {
                      mLocationManager.removeUpdates(mLocationListeners[i]);
                  } catch (Exception ex) {
                      Log.i(TAG, "fail to remove location listners, ignore", ex);
                  }
              }
          }
      } 
      private void initializeLocationManager() {
          Log.e(TAG, "initializeLocationManager");
          if (mLocationManager == null) {
              mLocationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
          }
      }
      }
  
  
  
  
  
  
  11-29 12:25:24.905: E/AndroidRuntime(18925): FATAL EXCEPTION: main
  11-29 12:25:24.905: E/AndroidRuntime(18925): java.lang.NullPointerException
  11-29 12:25:24.905: E/AndroidRuntime(18925):    at com.secure.call_block.MyService$LocationListener.onLocationChanged(MyService.java:57)
  11-29 12:25:24.905: E/AndroidRuntime(18925):    at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:252)
  11-29 12:25:24.905: E/AndroidRuntime(18925):    at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:185)
  11-29 12:25:24.905: E/AndroidRuntime(18925):    at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:201)
  11-29 12:25:24.905: E/AndroidRuntime(18925):    at android.os.Handler.dispatchMessage(Handler.java:99)
  11-29 12:25:24.905: E/AndroidRuntime(18925):    at android.os.Looper.loop(Looper.java:137)
  11-29 12:25:24.905: E/AndroidRuntime(18925):    at android.app.ActivityThread.main(ActivityThread.java:4424)
  11-29 12:25:24.905: E/AndroidRuntime(18925):    at java.lang.reflect.Method.invokeNative(Native Method)
  </code></pre>