JGuizard
3/17/2016 - 6:50 PM

Notification at date

Notification at date

/*USAGE
        Calendar calendar = Calendar.getInstance();
        /*DAILY
        calendar.set(Calendar.HOUR_OF_DAY, 19);
        calendar.set(Calendar.MINUTE, 35);
        calendar.set(Calendar.SECOND, 0);
        */
        //DELAYED
        calendar.add(Calendar.SECOND, 10);
        long firstTime = calendar.getTimeInMillis();
        Intent intent1 = new Intent(IntroActivity.this, AlarmReceiver.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(IntroActivity.this, 0,intent1, PendingIntent.FLAG_UPDATE_CURRENT);
        AlarmManager am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
        am.set(AlarmManager.RTC_WAKEUP, firstTime, pendingIntent);
        //am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);

*/

public class AlarmReceiver extends BroadcastReceiver
{
    @Override
    public void onReceive(Context context, Intent intent)
    {
        // TODO Auto-generated method stub
        long when = System.currentTimeMillis();
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        Intent notificationIntent = new Intent(context, IntroActivity.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);


        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Toast.makeText(context,"NOTIFICATION",Toast.LENGTH_SHORT).show();
        NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(
                context).setSmallIcon(R.drawable.ic_launcher.png)
                .setContentTitle("Alaram Fired")
                .setContentText("Events To be PErformed").setSound(alarmSound)
                .setAutoCancel(true).setWhen(when)
                .setContentIntent(pendingIntent)
                .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
        notificationManager.notify(1000, mNotifyBuilder.build());
        //MID++;

    }
    
  /*
    //AD THIS IN MANIFEST INSIDE APPLICATION TAG
          <receiver android:name=".services.AlarmReceiver"/>
      //AND THE PERMISSION OUTSIDE
    <uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
  */