我看了一个如何使用Alarm Manager进行调度任务的示例; source 1,source 2。但是我有点混淆了如何在特定的时间设置闹钟,因为根据我的理解,它只有15分钟或一天的间隔。我正在寻找的是我希望它在特定的时间重复并重复。
我找到了this,但是从我指定的时间开始,它已经复发了2分钟。以下是我的代码所看到的内容。
活动
AlarmManager alarmManager = (AlarmManager)c.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(c, AlarmReceiver.class);
PendingIntent alarmIntent = PendingIntent.getBroadcast(c, 0, intent, 0);
// Set the alarm to start at 3.46 PM
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 15);
calendar.set(Calendar.MINUTE, 46);
// setRepeating() lets you specify a precise custom interval--in this case,
// 1 day
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),AlarmManager.INTERVAL_FIFTEEN_MINUTES, alarmIntent);
广播接收器
@Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
Toast.makeText(context, "triggered", Toast.LENGTH_LONG).show();
}
已在AndroidManifest中设置<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
和<receiver android:name=".BroadCastRecevier"/>
。
答案 0 :(得分:1)
您可以设置确切的时间:
manager.setExact(AlarmManager.RTC, startTime.getTimeInMillis(), operation);
如果那个时间已经过去了,明天就定了
if (Calendar.getInstance().after(startTime)) {
startTime.add(Calendar.DATE, 1);
}
答案 1 :(得分:0)
必须先添加以下权限:
getStickerPoints(handlingSticker, bitmapPoints);
float x1 = bitmapPoints[0];
float y1 = bitmapPoints[1];
float x2 = bitmapPoints[2];
float y2 = bitmapPoints[3];
float x3 = bitmapPoints[4];
float y3 = bitmapPoints[5];
float x4 = bitmapPoints[6];
float y4 = bitmapPoints[7];
if (showBorder) {
canvas.drawLine(x1, y1, x2, y2, borderPaint);
canvas.drawLine(x1, y1, x3, y3, borderPaint);
canvas.drawLine(x2, y2, x4, y4, borderPaint);
canvas.drawLine(x4, y4, x3, y3, borderPaint);
}
if (showIcons) {
float rotation = calculateRotation(x4, y4, x3, y3);
if (handlingSticker.isDrawableSticker()) {
for (int i = 0; i < drawable_sticker_icons.size(); i++) {
BitmapStickerIcon icon = drawable_sticker_icons.get(i);
switch (icon.getPosition()) {
case BitmapStickerIcon.LEFT_TOP:
configIconMatrix(icon, x1, y1, rotation);
break;
case BitmapStickerIcon.RIGHT_TOP:
configIconMatrix(icon, x2, y2, rotation);
break;
case BitmapStickerIcon.LEFT_BOTTOM:
configIconMatrix(icon, x3, y3, rotation);
break;
case BitmapStickerIcon.RIGHT_BOTOM:
configIconMatrix(icon, x4, y4, rotation);
break;
case BitmapStickerIcon.TOP_CENTER:
configIconMatrix(icon, (x1 + x2) / 2, y2, rotation);
break;
case BitmapStickerIcon.BOTTOM_CENTER:
configIconMatrix(icon, (x3 + x4) / 2, y4, rotation);
break;
case BitmapStickerIcon.LEFT_CENTER:
configIconMatrix(icon, x3, (y1 + y3) / 2, rotation);
break;
case BitmapStickerIcon.RIGHT_CENTER:
configIconMatrix(icon, x4, (y2 + y4) / 2, rotation);
break;
}
icon.draw(canvas, borderPaint);
}
}
然后:
<uses-permission android:name="android.permission.WRITE_SETTINGS" ></uses-permission>
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" ></uses-permission>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" ></uses-permission>