title: Create push notification settings like Whatsapp "notification" settings android
body: <p>I am new in developing android app and learning to develop basic applications and features.
  I want to create notification setting just like WhtsApp has i.e.</p>
  
  <ol>
  <li>Notification Tone( List of all default tones)</li>
  <li>Vibrate: default(or my own custom: off,default, short, long)</li>
  </ol>
  
  <p>I want the basic feature like this app has when new notification is received in the device.
  I am using GCM to send and receive notifications.
  It would be great help. Thanks in advance.</p>
  
  <p>Notification menu that i want is like this:
   <a href="http://i.stack.imgur.com/vanda.jpg" rel="nofollow">http://i.stack.imgur.com/vanda.jpg</a></p>
  
  <p><strong>Edit:</strong></p>
  
  <p>SettingsActivity.java</p>
  
  <pre><code>import android.app.Activity;
  import android.app.Notification;
  import android.app.Service;
  import android.content.Context;
  import android.content.SharedPreferences;
  import android.content.SharedPreferences.Editor;
  import android.os.Bundle;
  import android.os.Vibrator;
  import android.view.Menu;
  import android.widget.CompoundButton; 
  import android.widget.Toast;
  import android.widget.ToggleButton;
  import android.widget.CompoundButton.OnCheckedChangeListener;
  
  public class SettingsActivity extends Activity {
  
  Vibrator vibrate;
  ToggleButton tb;
  boolean status= false;
  public static final String MyPREFERENCES = "MyPrefs";
  SharedPreferences prefs;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_settings);
      tb = (ToggleButton) findViewById(R.id.toggleButton1);
      prefs = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
      if (prefs.contains("vibrate")) {
          status=Boolean.parseBoolean(prefs.getString("vibrate", ""));
          if(status){
              tb.setChecked(true);
          }else{
              tb.setChecked(false);
          }
      }
  
      tb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  
          @Override
          public void onCheckedChanged(CompoundButton buttonView,
                  boolean isChecked) {
              // TODO Auto-generated method stub
              if (isChecked) {
                  Toast.makeText(getApplicationContext(), "ON",
                          Toast.LENGTH_LONG).show();
                  status= true;
                  Editor editor = prefs.edit();
                  editor.putString("vibrate", status+"");
                  editor.commit();
                  PreferencesData.saveString(getApplicationContext(), "vibrate", status+"");
              } else {
                  Toast.makeText(getApplicationContext(), "OFF",
                          Toast.LENGTH_LONG).show();
                  status= false;
                  Editor editor = prefs.edit();
                  editor.putString("vibrate", status+"");
                  editor.commit();
                  PreferencesData.saveString(getApplicationContext(), "vibrate", status+"");
  
              }
          }
      });
  }
  
  public boolean isVibrate(){
  
      return status;
  }
  }
  </code></pre>
  
  <p>GCMIntentService.java</p>
  
  <pre><code> //some code
  
  private static void generateNotification(Context context, String message) {
      int icon = R.drawable.ic_launcher;
      long when = System.currentTimeMillis();
      NotificationManager notificationManager = (NotificationManager)
              context.getSystemService(Context.NOTIFICATION_SERVICE);
      Notification notification = new Notification(icon, message, when);
  
      String title = context.getString(R.string.app_name);
  
      Intent notificationIntent = new Intent(context, MainActivity.class);
      // set intent so it does not start a new activity
      notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
              Intent.FLAG_ACTIVITY_SINGLE_TOP);
      PendingIntent intent =
              PendingIntent.getActivity(context, 0, notificationIntent, 0);
      notification.setLatestEventInfo(context, title, message, intent);
      notification.flags |= Notification.FLAG_AUTO_CANCEL;
  
      // Play default notification sound
      notification.defaults |= Notification.DEFAULT_SOUND;
  
      SettingsActivity stng = new SettingsActivity();
      Vibrator vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
  
      boolean vibStatus = stng.isVibrate();
  
      //notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "your_sound_file_name.mp3");
  
      // Vibrate if vibrate is enabled
      if(vibStatus){
      notification.defaults |= Notification.DEFAULT_VIBRATE;
      vibrator.vibrate(500);
      }
      else{
          vibrator.cancel();
      }
      notificationManager.notify(0, notification);      
  
  }
  </code></pre>