作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图让我的应用程序在指定的时间运行,但我无法让它工作。我可以在运行 adb shell dumpsys alarm
时看到未决警报,并且每次运行 AlarmActivity 时警报统计数据都会增加。
我在可以看到警报的地方添加了 adb shell dumpsys alarm
输出。我看不出有什么问题感谢帮助
这是我的 AlarmActivity 代码:
package net.dradge.alarm;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
public class AlarmActivity extends Activity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
}
protected void onResume(){
super.onResume();
this.setAlarm();
}
public class AlarmReceiver extends BroadcastReceiver{
public void onReceive(Context context, Intent intent){
Log.w("net.dradge.alarm", "Alarm received");
AlarmActivity.this.setAlarm();
}
}
private synchronized void setAlarm(){
Calendar date = Calendar.getInstance();
AlarmManager manager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
Intent alarmIntent = new Intent(this, AlarmReceiver.class);
PendingIntent operation = PendingIntent.getBroadcast(AlarmActivity.this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
manager.set(AlarmManager.RTC_WAKEUP, date.getTimeInMillis() + 30 * 1000, operation);
DateFormat df = DateFormat.getDateTimeInstance();
Log.w("net.dradge.alarm", "Alarm set to " + df.format(new Date(date.getTimeInMillis() + 30 * 1000)));
}
}
这是 list 代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.dradge.alarm"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".AlarmActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".AlarmActivity.AlarmReceiver"></receiver>
</application>
</manifest>
adb shell dumpsys 警报 当前警报管理器状态:
Realtime wakeup (now=1332181365617):
RTC_WAKEUP #2: Alarm{45260f00 type 0 com.android.providers.calendar}
type=0 when=1332231022777 repeatInterval=0 count=0
operation=PendingIntent{4521fdf8: PendingIntentRecord{45260e88 com.android.providers.calendar broadcastIntent}}
RTC_WAKEUP #1: Alarm{451d51b8 type 0 android}
type=0 when=1332201600000 repeatInterval=0 count=0
operation=PendingIntent{44f98c98: PendingIntentRecord{45084d80 android broadcastIntent}}
RTC_WAKEUP #0: Alarm{45222b40 type 0 com.google.android.gsf}
type=0 when=1332182126363 repeatInterval=1800000 count=0
operation=PendingIntent{45285370: PendingIntentRecord{44f58970 com.google.android.gsf broadcastIntent}}
RTC #1: Alarm{45142d08 type 1 android}
type=1 when=1332241200000 repeatInterval=0 count=0
operation=PendingIntent{4504aba8: PendingIntentRecord{4504ab70 android broadcastIntent}}
RTC #0: Alarm{451c1b90 type 1 android}
type=1 when=1332181380000 repeatInterval=0 count=0
operation=PendingIntent{450363c0: PendingIntentRecord{450548d8 android broadcastIntent}}
Elapsed realtime wakeup (now=505486995):
ELAPSED #0: Alarm{45201280 type 3 android}
type=3 when=505988995 repeatInterval=0 count=0
operation=PendingIntent{44ff4190: PendingIntentRecord{44f6b9a0 android broadcastIntent}}
Broadcast ref count: 0
Alarm Stats:
net.dradge.alarm
23ms running, 4 wakeups
4 alarms: flg=0x4 cmp=net.dradge.alarm/.AlarmActivity$AlarmReceiver
com.google.android.gsf
13965ms running, 280 wakeups
280 alarms: flg=0x4
com.android.providers.calendar
195ms running, 6 wakeups
6 alarms: act=com.android.providers.calendar.SCHEDULE_ALARM flg=0x4
android
105577ms running, 7 wakeups
6 alarms: act=android.intent.action.DATE_CHANGED flg=0x20000004
2 alarms: act=com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD flg=0x4
561 alarms: act=android.intent.action.TIME_TICK flg=0x40000004
305 alarms: act=com.android.server.ThrottleManager.action.POLL flg=0x4
5 alarms: act=com.android.service.Watchdog.CHECKUP flg=0x4
最佳答案
我认为你的接收器应该声明为
<receiver android:name=".AlarmActivity$AlarmReceiver"></receiver>
因为它是一个内部类。
关于安卓闹钟从未收到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9711026/
背景 我最近在 merge 期间遇到了一个意外未 merge 的文档文件的问题。 无论出于何种原因,我搞砸了 merge 并有效地删除了文件(和其他几个文件),因为我忘记了它们的存在。 现在我想查看我
我在我的网站上使用旧的 mysql 版本和 php 版本 4。 我的表结构: | orders_status_history_id | orders_id | orders_status_id |
我是一名优秀的程序员,十分优秀!