0

I have the following code (abbreviated to the relevant part). If I set the alarm manger on a specific time and when this time comes the notification doesn't show up. I want to set date like sun-mon-tue.

Code Snippet :

public class service extends Service {

    private int Period_You_Want_in_MilliSecond = 30 * 1000;
    Calendar calender ;
    SimpleDateFormat format ;

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        DataBase DB=new DataBase(this);
        //get row from database where id=1
        final CourseClass C=DB.getCousre(1);

        calender = Calendar.getInstance();
        format = new SimpleDateFormat("hh:mm aa");

        Toast.makeText(getApplicationContext(), "service entered", Toast.LENGTH_LONG).show();

        final Handler h = new Handler();
        Runnable r = new Runnable() {

            @Override
            public void run() {


                String current_time = format.format(calender.getTime());
                //Toast.makeText(getApplicationContext(), ""+current_time,Toast.LENGTH_LONG).show();

                //check if the row reterned if filed name has data lenght>0 return True
                if(C.getName().length()>0){
                    if(current_time.equals("01:24 PM")){
                        //Toast.makeText(getApplicationContext(), "TIMER",Toast.LENGTH_LONG).show();

                        show_notification();

                    }
                }
                h.postDelayed(this,Period_You_Want_in_MilliSecond);
            }
        };      


        h.post(r);

        return super.onStartCommand(intent, flags, startId);
    }
}
Aleksander Lidtke
  • 2,876
  • 4
  • 29
  • 41
  • and here is my create notification method public void show_notification(){ NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Notification noti = new Notification(R.drawable.ic_launcher, "Update !!!", 0); Intent intent = new Intent(getApplicationContext(), reciever.class); PendingIntent Pintent = PendingIntent.getActivity(service.this, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); noti .defaults = Notification.DEFAULT_SOUND; noti.setLatestEventInfo(service.this, "My APP", "New Update is found",Pintent); manager.notify(1, noti); } – Moh'd Qassrawi Jan 11 '14 at 12:04

1 Answers1

0

You are not using the AlarmManager, you are using a Handler. Take a look at this example.

Community
  • 1
  • 1
Robin Dijkhof
  • 18,665
  • 11
  • 65
  • 116