Android每月提醒应用程序

时间:2011-10-02 17:29:47

标签: android

我正在创建一个应用程序,其中需要在数据库中存储定期提醒。我已将提醒记录存储在数据库中,用户在每月的哪一天提到他必须在名为alert的表中执行其任务。现在我想要一些服务,它可以在用户设置的那一天每个月提醒用户这个任务。我已经看过警报管理器和其他选项,但无法弄清楚一些具体的方法。有人可以帮助我吗? 一切都完成了。我陷入了最后一道障碍。我的应用程序启动因为这个待处理的任务而停滞不前。任何人都可以帮忙吗?

非常感谢, Navraj singh

1 个答案:

答案 0 :(得分:0)

您的应用程序的一个很好的例子

访问http://www.vogella.de/articles/AndroidServices/article.html

    public void startAlert(View view) {
    EditText text = (EditText) findViewById(R.id.time);// In this text box
            //you will give the time in seconds you can change it according to your 
            //need.Like getting this text from database as you need.
    int i = Integer.parseInt(text.getText().toString());
    Intent intent = new Intent(this, MyBroadcastReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(
            this.getApplicationContext(), 234324243, intent, 0);
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
            + (i * 1000), pendingIntent);
    Toast.makeText(this, "Alarm set in " + i + " seconds",
            Toast.LENGTH_LONG).show();
}

以上功能在给定时间后开始报警。

这是广播接收器类

  public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Toast.makeText(context, "Don't panik but your time is up!!!!.",
            Toast.LENGTH_LONG).show();
    // Vibrate the mobile phone
    Vibrator vibrator = (Vibrator)    

            context.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(2000);
}

 }
相关问题