myq_26 2013-06-09 10:24 采纳率: 16.7%
浏览 2134
已采纳

字符串的date转换为alarm

我想设置alarms 功能,我把时间存储在一个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);        
    }

我如何从date 格式中提取时间然后在通知中设置?

  • 写回答

2条回答 默认 最新

  • kity 2013-06-09 10:40
    关注
    AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); 
      SimpleDateFormat  dt = new SimpleDateFormat("hh:mm"); 
      Date date = new Date();  //当前时间日期
         try {
                     Date dateTime = dt.parse(str);
             date.setHours(dateTime.getHours());
                 date.setMinutes(dateTime.getMinutes());
    
         } catch (ParseException e) {
                e.printStackTrace();
        }         
     am.set(AlarmManager.RTC_WAKEUP,date.getTime(), contentIntent);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题