2

我们可以在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”的属性,因此我们没有设置闹钟日期。你有什么想法通过使用意图 ve 闹钟来解决这个问题

感谢您的创意回复

4

3 回答 3

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);
于 2013-07-12T09:46:59.977 回答
1

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

<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
于 2013-07-12T09:52:26.637 回答
-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"/>
于 2017-10-25T09:18:42.167 回答