0

我正在尝试设置警报。我有时间存储在 cvs 文件中。它们的格式为 hh:mm,例如 02:13。我想为这个时间设置闹钟

使用以下代码

  SimpleDateFormat  dt = new SimpleDateFormat("hh:mm"); 
      dt.parse(str); // GET TIME HERE

NotificationManager manger = (NotificationManager) this.getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(R.drawable.launcher, "Mosque Prayer Times", time);
        PendingIntent contentIntent = PendingIntent.getActivity(this.getActivity(), 0, new Intent(this.getActivity(), AlarmReceiver.class), 0);
        notification.setLatestEventInfo(this.getActivity(), name, title, contentIntent);
        notification.flags = Notification.FLAG_INSISTENT;
        notification.sound = Uri.parse("android.resource://com.trib.app.mosqueprayertimes/raw/adhan.mp3");
        manger.notify(id, notification);        
    }

我发现很难从这种日期格式中提取“时间”并将其设置在我的通知中

4

1 回答 1

0

你有没有试过这个......

 SimpleDateFormat  dt = new SimpleDateFormat("hh:mm"); 
     Date date=  dt.parse(str); // GET TIME HERE
    Calender cal=Calender.getInstance();
    cal.setTime(date);
    String hours=cal.get(Calendar.HOUR);
    String minutes=cal.get(Calendar.MINUTE);
于 2013-02-17T15:57:51.363 回答