I designed an alarm service application. In that application, whenever an alarm starts, it will show in the notification bar. The problem is that I want to stop the alarm as well as the notification, whenever I drag the notification bar.
Here's my code:
if(pYear==pYear2 && pMonth==pMonth2 && pDay==pDay2 && pHour==pHour2 && pMin==pMin2 && pSec==psec2)
{
Context context = getApplicationContext();
Intent notifyIntent = new Intent(context, MyAlarmService.class);
PendingIntent intent1 =PendingIntent.getActivity(MyAlarmService.this, 0, notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
Notification notifyDetails = new Notification(R.drawable.ic_launcher,"New Alert, Click Me!",System.currentTimeMillis());
notifyDetails.setLatestEventInfo(context, "Alaram", "Get back to Application on clicking me", intent1);
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
AudioManager am=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
am.setMode(AudioManager.MODE_NORMAL);
try
{
mp.setDataSource(getApplicationContext(), ringtoneUri);
mp.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
mp.prepare();
mp.setLooping(true);
mp.start();
}
catch(Exception e)
{
//exception caught in the end zone
}
to play notification sounds you should use notifyDetails.defaults |= Notification.DEFAULT_SOUND;