Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从sqlite数据库检查日期?_Android_Sqlite - Fatal编程技术网

Android 如何从sqlite数据库检查日期?

Android 如何从sqlite数据库检查日期?,android,sqlite,Android,Sqlite,我有一个sqlite数据库表,它可以联系朋友和他的联系人以及他们的出生日期。当数据库中的任何日期与当前日期匹配时,我想发出警报。请任何人帮助我如何完成此任务。 事实上,我想每天两次约会,请建议我 我正在使用这个代码 private void setAlarm(String name,String date) { String[] arrdob =date.split("/"); Calendar cal = Calendar.getInstance(); //for

我有一个sqlite数据库表,它可以联系朋友和他的联系人以及他们的出生日期。当数据库中的任何日期与当前日期匹配时,我想发出警报。请任何人帮助我如何完成此任务。 事实上,我想每天两次约会,请建议我

我正在使用这个代码

private void setAlarm(String name,String date)
{
    String[] arrdob =date.split("/");
    Calendar cal = Calendar.getInstance();       //for using this you need to import java.util.Calendar;

    // add minutes to the calendar object
    cal.set(Calendar.MONTH,Integer.parseInt(arrdob[1]));
    cal.set(Calendar.YEAR, Integer.parseInt(arrdob[2]));                
    cal.set(Calendar.DAY_OF_MONTH,Integer.parseInt(arrdob[0]));
    cal.set(Calendar.HOUR_OF_DAY,14);
    cal.set(Calendar.MINUTE,35);
    System.out.println("1");

    Intent alarmintent = new Intent(getApplicationContext(), AlarmReceiver.class);
    alarmintent.putExtra("title","B'Day Alarm");
    alarmintent.putExtra("subject","Hi!Todays "+name+" B'Day");

    PendingIntent sender = PendingIntent.getBroadcast(getApplicationContext(), HELLO_ID,
    alarmintent,PendingIntent.FLAG_UPDATE_CURRENT |  Intent.FILL_IN_DATA);
    //VERY IMPORTANT TO SET FLAG_UPDATE_CURRENT... this will send correct extra's informations to 
    //AlarmReceiver Class
   // Get the AlarmManager service               
    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
}
在将值插入数据库时调用此方法。 AlarmReceiver类别如下:

private static int NOTIFICATION_ID = 1;

@Override
public void onReceive(Context context, Intent intent) //
{
    // NotificationManager mNotificationManager = 
    System.out.println("2");
   //context.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationManager manger = (NotificationManager)     
    context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = 
        new Notification(R.drawable.ic_launcher, "Combi Note",System.currentTimeMillis());
    PendingIntent contentIntent = PendingIntent.getActivity(context, 
            NOTIFICATION_ID, 
            new Intent(context, AlarmReceiver.class), 0);

    Bundle extras=intent.getExtras();
    String title=extras.getString("title");
 //here we get the title and description of our Notification
    String note=extras.getString("subject");
    notification.setLatestEventInfo(context, note, title, contentIntent);
    notification.flags = Notification.FLAG_INSISTENT;
    notification.defaults |= Notification.DEFAULT_SOUND;
//在这里,我们为我们的 //通知

    // The PendingIntent to launch our activity if the user selects this notification
    manger.notify(NOTIFICATION_ID++, notification);
}

您是否正在尝试执行生日警报之类的操作?是的,我正在尝试为插入时保存在sqlite中的每个出生日期设置警报管理器。只需比较两个日期,如:date firstDate=new date();日期secondDate=新日期();firstDate.compareTo(secondDate)@Zaz Gmy:当我比较日期时,请正确地建议我。为什么setAlarm不工作?试试这个int diff=firstDate.compareTo(secondDate);如果(diff==0){notify user}其他{date not same}您是否尝试执行生日警报之类的操作?是的,我正在尝试为插入时保存在sqlite中的每个出生日期设置警报管理器。只需比较两个日期,如:date firstDate=new date();日期secondDate=新日期();firstDate.compareTo(secondDate)@Zaz Gmy:当我比较日期时,请正确地建议我。为什么setAlarm不工作?试试这个int diff=firstDate.compareTo(secondDate);if(diff==0){notify user}else{date not same}