Accessing RingtoneManager

From an Activity, I am trying to use the RingtoneManager and play a ringtone, and it works fine. However the app crashes when I try to stop the ringtone.

Here is the Activity code:

public class Time_Date extends FragmentActivity {

    protected void onCreate(Bundle savedInstanceState) {

        Uri alarmUri = 

        if (alarmUri == null) {
            alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        final Ringtone ringtone = RingtoneManager.getRingtone(this, alarmUri);;

        Intent receive = getIntent();

        int vibrator = receive.getIntExtra("vibrator",1);

        if (vibrator==1) {
            Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);

And, now when I define an onclick and add this method to stop the ringtone, it crashes, What’s the best fix to this ?

public void dismissButton(View view) {

Source: android

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.