package com.androidbegin.buttonclicktutorial;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.widget.Toast;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;


public class AlarmReceiver extends BroadcastReceiver 
{

	/*
	@Override
	public void onReceive(Context arg0, Intent arg1) 
	{
		Toast.makeText(arg0, "Alarm received!", Toast.LENGTH_LONG).show();

	}
	*/
	@Override
	public void onReceive(Context context, Intent intent) 
	{
	
			long alarmId = intent.getLongExtra("index", -1);
			String titre = intent.getStringExtra("titre");
	/*
			AlarmMsg alarmMsg = new AlarmMsg(alarmMsgId);
			alarmMsg.setStatus(AlarmMsg.EXPIRED);
			alarmMsg.persist(RemindMe.db);
	
			Alarm alarm = new Alarm(alarmId);
			alarm.load(RemindMe.db);
	/*
	 */
			Notification n = new Notification(R.drawable.ic_launcher, titre, System.currentTimeMillis());
			PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(), 0);
	
			n.setLatestEventInfo(context, "Remind Me", titre, pi);		
			
			/*
			if (RemindMe.isVibrate()) 
			{
				n.defaults |= Notification.DEFAULT_VIBRATE;
			}
			
			if (alarm.getSound())
			{
				n.sound = Uri.parse(RemindMe.getRingtone());
				//		n.defaults |= Notification.DEFAULT_SOUND;
			}		*/
			
			n.flags |= Notification.FLAG_AUTO_CANCEL;		
			NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
			nm.notify((int)alarmId, n);
			
			
			//Intent myIntent=new Intent(context, ringtone.class);   
			//myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
			//context.startActivity(myIntent); 
			
			
	}
}

	
	
	
	
	
	

