gpt4 book ai didi

安卓闹钟从未收到

转载 作者:行者123 更新时间:2023-11-29 02:06:35 25 4
gpt4 key购买 nike

我试图让我的应用程序在指定的时间运行,但我无法让它工作。我可以在运行 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com