当我试图将当前日期与sqlite中存储的日期进行比较时,我在代码中所做的错误是什么?

时间:2014-05-28 19:53:24

标签: android date android-sqlite android-notifications

我有一个Android应用程序,它使用sqlite数据库存储数据,其中一个字段为 match_date

我想要的是三个步骤

  • 首先以正确的方式检索存储的日期。
  • 秒,比较当前日期和存储日期。
  • 第三个在比较2个日期之后创建通知,如果是 答案是真的,必须出现通知才能通知用户。

第三步我将解决现在我的问题是解决前两个步骤

我将不胜感激任何帮助。

我的通知显示的是2014-06-26数据库中存储的最后一个日期以及我不知道其含义的数字23.

的logcat

05-21 17:37:55.917: E/inside the Shownotification(1306): index is4
05-21 17:37:55.917: E/inside the Shownotification(1306): date is2014
05-21 17:37:55.921: E/inside the displayNotification(1306): inside displayNotification
05-21 17:37:55.933: E/inside the Shownotification(1306): index is4
05-21 17:37:55.933: E/inside the Shownotification(1306): date is2014
05-21 17:37:55.933: E/inside the displayNotification(1306): inside displayNotification

public Cursor getAllRows(PendingIntent notificationIntent) {
        String where = null;

        c = database.query(true, TABLE_NAME, ALL_KEYS, where, null, null, null,
                null, null);
        if (c != null) {

            c.moveToFirst();


            while (!c.isAfterLast()) {
                listdetail = new ItemDetails();

                listdetail.setTeam1(c.getString(c.getColumnIndex("team1")));

                listdetail.setTeam2(c.getString(c.getColumnIndex("team2")));

                listdetail.setDate_match(c.getString(c
                        .getColumnIndex("match_date")));




                 // if the pick up date from the database is equal to the current date the notification will pop up 

                long i =  (new Date().getTime()/1000);

                 //// from the internet 
                 int index = c.getColumnIndex("match_date");

                // Toast.makeText(this, c.getColumnIndex("match_date"), Toast.LENGTH_LONG).show();

                 long date = c.getLong(index);
                 ////////
                Log.e("inside the Shownotification", "index is" + index);


                //if(time == i){

                     Log.e("inside the Shownotification", "date is" + date);

                    NotificationCompat.Builder builder = new Builder(
                            getApplicationContext());
                    Notification notification = builder
                            .setSmallIcon(R.drawable.fifa_2014_4)
                            .setContentTitle("Up Comming Match")
                            .setContentText(
                                    c.getString(c.getColumnIndex("match_date"))
                                            + (c.getColumnIndex("team1"))
                                            + (c.getColumnIndex("team2"))).build();


                    displayNotification(notification);




                c.moveToNext();
        }

0 个答案:

没有答案