如何使用AlarmClock在android中设置闹钟日

时间:2013-07-12 09:43:24

标签: android android-intent alarm

我们可以在android

中创建意图警报
        Intent i = new Intent(AlarmClock.ACTION_SET_ALARM); 
    i.putExtra(AlarmClock.EXTRA_MESSAGE, "New Alarm"); 
    i.putExtra(AlarmClock.EXTRA_HOUR, 23); 
    i.putExtra(AlarmClock.EXTRA_MINUTES, 11); 

我们想在创建闹钟时添加day属性。但是,AlarmClock不包含有关“Extra_Day_Week”的属性,因此我们没有设置警报日。您是否有任何想法通过使用intent ve alarmclock解决此问题

感谢您的创意回复

3 个答案:

答案 0 :(得分:1)

这可以帮助你:

    Calendar cal = Calendar.getInstance();

    cal.setTimeInMillis(System.currentTimeMillis());
    cal.clear();
    cal.set(2012,2,8,18,16);// instead of these lines you can use below lines in comment

    //cal.set(Calendar.HOUR_OF_DAY, 16);
    //cal.set(Calendar.MINUTE, 25);
    //cal.set(Calendar.SECOND, 0);
    //cal.set(Calendar.MILLISECOND, 0);

    AlarmManager alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(this, AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);

    alarmMgr.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);

答案 1 :(得分:1)

您可能忘记了在AndroidManifest.xml中添加的权限

<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>

答案 2 :(得分:-1)

该属性称为EXTRA_DAYS

你可以像这样使用它:

ArrayList<Integer> alarmDays = new ArrayList<>();
alarmDays.add(Calendar.MONDAY);
alarmDays.add(Calendar.WEDNESDAY);
alarmDays.add(Calendar.FRIDAY);

Intent i = new Intent(AlarmClock.ACTION_SET_ALARM);
i.putExtra(AlarmClock.EXTRA_DAYS, alarmDays);
i.putExtra(AlarmClock.EXTRA_HOUR, 23);
i.putExtra(AlarmClock.EXTRA_MINUTES, 11);
i.putExtra(AlarmClock.EXTRA_MESSAGE, "New Alarm");    
i.putExtra(AlarmClock.EXTRA_VIBRATE, true);

startActivity(i);

任何其他用户发现此信息,请勿忘记请求权限! (在清单中)

<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>