Проверьте сейчас, я обновил код.
Вот код для CountDownTimer.
и когда время истекает, оно отправляет уведомление.
Вы можете использовать его в Сервисе или в обычной Активности.
public String ns = Context.NOTIFICATION_SERVICE;
public NotificationManager mNotificationManager;
Notification notification;
PendingIntent contentIntent;
Intent notificationIntent;
public class Main extends Activity{
private final long startTime = 50000;
private final long interval = 1000;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
int time=Integer.parseInt(editText.getText().toString());
time=time*1000;
startTime = time;
// place this code on button listener if you want.
countDownTimer = new MyTimer(startTime, interval);
}
}
public class MyTimer extends CountDownTimer
{
public MyTimer(long startTime, long interval)
{
super(startTime, interval);
}
@Override
public void onFinish()
{
mNotificationManager = (NotificationManager) getSystemService(ns);
notificationIntent = new Intent(this, MyActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification = new Notification(R.drawable.icon,"Time up..", System.currentTimeMillis());
notification.setLatestEventInfo(this, "CallingaCab", "YOUR TIME COMPLETED", contentIntent);
mNotificationManager.notify(0, notification);
startActivity(notificationIntent);
}
@Override
public void onTick(long millisUntilFinished)
{
//Perform what do you want on each tick.
}
}
}