My alarm code is working fine as default ringtone is playing well on time. But not able to stop the alarm tone. In receiver class I inserted the following code.
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
Ringtone r = RingtoneManager.getRingtone(context, notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
I also inserted the code for cancel the alarm in main class, which is also working well with the code
alarmMgr.cancel(pendingIntent);
But once the default ringtone start playing and user want to stop this by stop button then it is not working. In main class with stopbutton.setOnClickListener I inserted the following code
Intent intent = new Intent(getBaseContext(), Reciver.class);
stopService(intent);
I think it can be stop by r.stop(); but how should I use it in stop button.