Android напоминание! - PullRequest
       1

Android напоминание!

3 голосов
/ 26 мая 2011

Я хотел бы спросить, какой сервис и как использовать, чтобы сделать напоминание в Android ... Скажем: через 10 минут показывать мне уведомление в панели уведомлений ...

Спасибо за ваш ответ

Ответы [ 3 ]

9 голосов
/ 26 мая 2011

Очевидно, что вы должны использовать AlarmManager для настройки того, что должно быть выполнено в данный PERIOD.

AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, OnAlarmReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 
SystemClock.elapsedRealtime(), PERIOD, pi);

, где PERIOD - ваше время для чего-то, что должно быть выполнено в OnAlarmReceiver.А затем просто реализуйте метод в

@Override
public void onReceive(Context context, Intent intent) {
    NotificationManager nm = (NotificationManager);
    context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification();
    notification.tickerText = "10 Minutes past";
    nm.notify(0, notification);
}

Наслаждайтесь.

2 голосов
/ 26 мая 2011

Вы должны использовать AlarmManager.С его помощью вы можете запланировать намерение быть доставленным.Создайте BroadcastReceiver, чтобы получить его и показать уведомление.

1 голос
/ 26 мая 2011

Думаю, что-то вроде этого, вы запускаете исполняемый файл через 10 минут и открываете уведомление в коде запускаемого файла.

Runnable reminder = new Runnable()
{
    public void run()
    {
        int NOTIFICATION_ID = 1324;
        NotificationManager notifManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        Notification note = new Notification(R.drawable.icon, "message", System.currentTimeMillis());

        // Add and AUTO_CANCEL flag to the notification, 
        // this automatically removes the notification when the user presses it
        note.flags |= Notification.FLAG_AUTO_CANCEL;    

        PendingIntent i = PendingIntent.getActivity(this, 0, new Intent(this, ActivityToOpen.class), 0);

        note.setLatestEventInfo(this, "message", title, i);
        notifManager.notify(NOTIFICATION_ID, note);
    }
};

Handler handler = new Handler();
handler.postDelayed(reminder, 600000);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...